首页 > 解决方案 > 来自 Flutter Widget 的高分辨率图像

问题描述

在我的应用程序中,我需要从屏幕上显示的小部件创建图像。
我使用以下代码使用RepaintBoundary.
但我得到的图像是 72 PPI。有什么方法可以获得更高分辨率的图像吗?

Future<void> takePicture() async {
  RenderRepaintBoundary boundary = genKey.currentContext.findRenderObject();
  ui.Image image = await boundary.toImage();
  final directory = (await getApplicationDocumentsDirectory()).path;
  ByteData byteData = await image.toByteData(format: ui.ImageByteFormat.png);
  Uint8List pngBytes = byteData.buffer.asUint8List();
  File imgFile = new File('$directory/photo.png');
  imgFile.writeAsBytes(pngBytes);
}

标签: imageflutter

解决方案


使用这条线将提高“boundary.toImage(pixelRatio:10.0)”pixelRatio 使用双倍来提高你想要的质量。


推荐阅读