在開發(fā)過程中,可能服務(wù)端要你上傳base64編碼格式的圖片,那么你就需要進行base64編碼的轉(zhuǎn)換,如何進行截屏并且進行base64編碼的轉(zhuǎn)換,下邊的代碼可能會幫到你。
RenderRepaintBoundary boundary =
rootWidgetKey.currentContext.findRenderObject();
final image = await boundary.toImage(pixelRatio: 1.0);
ByteData byteData = await image.toByteData(format: ImageByteFormat.png);
Uint8List pngBytes = byteData.buffer.asUint8List();
String bs64 = base64Encode(pngBytes);
String bs64Image = "data:image/png;base64,"+bs64;