我正在使用来自Flutter相机插件的示例代码。我想在捕获图像并将其存储在
我不确定是否有内置功能可用。在他们的文档中没有找到任何信息。
我尝试像下面这样使用Image插件来实现它,但是它无效。当您使用它时,整个应用程序停止运行。
imageFile
变量中后减小图像大小。我不确定是否有内置功能可用。在他们的文档中没有找到任何信息。
我尝试像下面这样使用Image插件来实现它,但是它无效。当您使用它时,整个应用程序停止运行。
void onTakePictureButtonPressed() {
takePicture().then((XFile? file) {
if (mounted) {
setState(() {
resizeImage(file) // this is what I tried to add to achieve it...
imageFile = file;
videoController?.dispose();
videoController = null;
});
if (file != null) showInSnackBar('Picture saved to ${file.path}');
}
});
}
XFile resizeImage(img) {
var image = imageP.decodeJpg(File(img.path).readAsBytesSync());
var thumbnail = imageP.copyResize(image, width: 400);
File(img.path).writeAsBytesSync(imageP.encodeJpg(thumbnail));
return XFile(img.path);
}
image_crop
的包的成功案例。它不是用来缩小尺寸的,而是用来裁剪的。如果你需要添加裁剪屏幕,你可以使用它。主要函数cropImage
有 maxHeight 和 maxWidth,这就是你所需要的。https://pub.dev/packages/image_cropper - Mol0ko