从 Flutter Image_Picker 插件获取的图像尺寸太大 [英] Image size taken from Flutter Image_Picker plugin is way too big

查看:43
本文介绍了从 Flutter Image_Picker 插件获取的图像尺寸太大的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在相机上使用自动对焦,它可以在 image_picker 插件上使用.但是,当我打电话时:

I want to use auto-focus on the camera, which is available on the image_picker plugin. However, when I call:

var bytes = new File(imagePath);
var enc = await bytes.readAsBytes();
print(enc.length);

我得到:5121126

I got: 5121126

当我想编码成 json 发送到 API 服务器时至少需要 10 秒:

which takes at least 10 seconds when I want to encode into json to send to an API server:

var body = json.encode({
      'image' : enc
})

相比之下,有了相机插件,我的字节数组只有420685,小了10倍,但是没有自动对焦功能.

In contrast, with the camera plugin, my byte array is only 420685, which is 10 times smaller, but it doesn't have the auto-focus feature.

我能得到一些关于如何从 image_picker 中减小字节数组大小的建议吗?谢谢.

Can I get some advice on how to reduce the size of the byte array from image_picker? Thank you.

推荐答案

camera 插件有 3 个默认分辨率,您可能选择或默认为较低的分辨率(低于硬件的全分辨率).

The camera plugin has 3 default resolutions, and you are probably selecting or defaulting to a lower resolution (than the hardware's full resolution).

image_picker 插件没有这些预设,但在 pickImage 方法上有一些可选参数(maxWidth最大高度).尝试将其中一个或两个设置为 VGA 类型的分辨率(640、480,甚至 800、600),看看这是否会减小捕获图像的大小.

The image_picker plugin doesn't have these presets, but does have some optional arguments on the pickImage method (maxWidth and maxHeight). Experiment setting one or both of these to VGA type resolutions (640, 480, even 800, 600) to see if this reduces the size of the captured image.

还有一个名为 image 的包,可让您对图像进行后处理.主页上的示例进行了调整大小,保持纵横比.

There's also a package called image which would allow you to post-process the image. The sample on the main page does a resize, maintaining aspect ratio.

这篇关于从 Flutter Image_Picker 插件获取的图像尺寸太大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆