[英]Capture a snapshot of an upploaded video and save image.png file - JQUERY
[英]Convert Widget to Image.png and Save it In Created Directory Flutter
我希望我的應用程序在安裝時首先在內部存儲中創建特定目錄,並在單擊時創建一個按鈕,將特定小部件(屏幕)轉換為 image.png,然后將其保存在該創建的目錄中。
我需要完整的代碼。 我一直在尋找,但我還沒有找到有效的方法。
此功能是您對小部件進行截圖並保存在本地的全部需要:
static GlobalKey _repaintKey = GlobalKey();
Widget _yourWidget(){
return Stack(
key: _repaintKey,
children: [
],
);
}
Future<void> _takeScreenShot(context) async {
RenderRepaintBoundary boundary = _repaintKey.currentContext.findRenderObject();
ui.Image image = await boundary.toImage();
ByteData byteData = await image.toByteData(format: ui.ImageByteFormat.png);
Uint8List pngBytes = byteData.buffer.asUint8List();
final path = join(
(await getTemporaryDirectory()).path, "screenshot${DateTime.now().toIso8601String()}.png");
File imgFile = File(path);
imgFile.writeAsBytes(pngBytes).then((value) {
Navigator.of(context).pushNamed(Routes.uploadImage, arguments: value.uri.path);
}).catchError((onError) {
print(onError);
});
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.