Flutter 將Widget 轉換成 Png圖

flutter 將視圖Widget 生成成Png 流程

  1. 將需要生成圖片的Widget 使用RepaintBoundary包裹起來,并給定globalkey。

  2. 通過globalKey獲取renderObject .轉成圖就好

RepaintBoundary(
  key: PageManageUtil().generateKey(pageIndex),
  child: _inheritedInfo.dmsStackViewFromMap[pageIndex],
)
RenderRepaintBoundary boundary = _pageGlobalKey.currentContext.findRenderObject();
ui.Image image = await boundary.toImage(pixelRatio: 3.0);
ByteData byteData = await image.toByteData(format: ui.ImageByteFormat.rawRgba);
Uint8List _uInt8List = byteData.buffer.asUint8List();
Image.memory(_uInt8List, width: 100, height: 177)
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容