flutter 截图获取设备像素比

学习笔记 yekong 63℃

手机截图功能,第一个写pixelRatio比例为1,发现截图很模糊,仔细查阅,才发现需要获取当前像素比

try {
        RenderRepaintBoundary boundary =
            rootWidgetKey.currentContext.findRenderObject();
        var dpr = window.devicePixelRatio;
        var image = await boundary.toImage(pixelRatio: dpr);
        ByteData byteData = await image.toByteData(format: ImageByteFormat.png);
        Uint8List pngBytes = byteData.buffer.asUint8List();
        final result = await ImageGallerySaver.saveImage(pngBytes);
        BotToast.showText(
            text: ObjectUtil.isEmpty(result) ? '保存失败,请稍后再试' : '保存相册成功');
      } catch (e) {
        print(e);
      }

 

喜欢 (1)