gpt4 book ai didi

flutter - 抖动的图像处理导致像素化

转载 作者:行者123 更新时间:2023-12-03 03:56:02 24 4
gpt4 key购买 nike

将文件上传到服务器之前,需要处理照片并调整大小/裁剪图像到640/420(15:10)的抖动项目,但是这些项目看起来质量太高且像素化。

      img.Image image = img.decodeImage(a2);
double width = (image.height / 10) * 15;
image = img.copyCrop(image, ((image.width - width) / 2).round(), 0, width.round(), image.height);
resized = img.encodeJpg(img.copyResize(image, width:640, interpolation: img.Interpolation.cubic));

目前使用 camera以720p(1280x720)拍摄,并使用 image插件进行裁剪并使用平均插值调整大小。

我主要想知道这是处理图像处理以保持最高质量的最佳方法,还是针对此用例是否有更好的方法。

最佳答案

您应该尝试这种方法,我一直在为自己使用以下方法,它的工作方式就像魅力一样,图像也不会损失任何质量,并且尺寸过于压缩

final _tempDir = await getTemporaryDirectory();
final _path = _tempDir.path;
im.Image imageFile = im.decodeImage(_file.readAsBytesSync());
mealID = Uuid().v4();
final compressedImageFile = File('$_path/img_$mealID.jpg')
..writeAsBytesSync(im.encodeJpg(imageFile, quality: 80));
setState(() {
_file = compressedImageFile;
});

上面的方法用于压缩图像,并用于从图库/相机捕获图像,我正在使用以下方法。

Future getImageFromCamera() async {
Navigator.pop(context);
var image = await ImagePicker.pickImage(
source: ImageSource.camera,
imageQuality: 50,
/*you can set max height and/or width here as well just by setting value for maxHeight and/or maxWidth argument*/
);
setState(() {
_file = image;
});
await compressImage();
}

Future getImageFromGallery() async {
Navigator.pop(context);
var image = await ImagePicker.pickImage(
source: ImageSource.gallery,
imageQuality: 50,
);
setState(() {
_file = image;
});
await compressImage();
}

关于flutter - 抖动的图像处理导致像素化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61250338/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com