在没有从相册或相机中取出图像的情况下,正确的保存 Image
到设备的方法是什么?
在 PageA 中,有一个相机按钮允许用户捕获图像。一旦图像被捕获,它将进入 PageB(EditImagePage)。一旦用户完成编辑图像,它将返回到 PageA,并保存图像到设备。
PageA
@override
userImage(File images) async { // when user has captured image, it will run this code
if (images != null) {
Image image = await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => EditImagePage(images.path), // go to edit image page
));
// convert image to File
// call copyImage function
} else {
}
}
页面B
IconButton(
icon: Icon(Icons.check),
onPressed: () async {
Uint8List bytes = await _controller.exportAsPNGBytes();
var image = Image.memory(bytes);
return Navigator.pop(context, image); // bring Image back to PageA
}),
我有这段用于将图像保存到设备的代码。如何将它改为保存文件?
Future<File> copyImage(File image) async {
var savedDir = await getApplicationDocumentsDirectory();
String appDocPath = savedDir.path;
var fileName = FileUtils.basename(image.path);
return await image.copy('$appDocPath/' + '$fileName');
}
imagePath
转换为File
的问题 - undefined