Flutter截取屏幕信息并保存为图片
在Flutter中,可以通过将需要截取的内容使用RepaintBoundary包裹起来,并设置一个GlobalKey,使用此global key获取要截取内容的渲染对象,调用其toImage方法,转换成ByteData类型的数据,并最终转化为Uint8List类型。
RenderRepaintBoundary boundary = _globalKey.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();