Android图片压缩不完全加载到内存

标签 android performance image-compression

有什么方法可以在不将图像完全加载到内存的情况下压缩图像? 据我了解 BitmapFactory.decodeStream 和类似的方法将所有内容加载到内存中,只有在加载整张图片后才能通过 Bitmap.compress

进行压缩

我的任务是将图片从android发送到服务器

最佳答案

你可以使用 BitmapRegionDecoder只读取原始图像的一部分,然后将每个部分分别压缩和上传。

BitmapRegionDecoder can be used to decode a rectangle region from an image. BitmapRegionDecoder is particularly useful when an original image is large and you only need parts of the image.

To create a BitmapRegionDecoder, call newInstance(...). Given a BitmapRegionDecoder, users can call decodeRegion() repeatedly to get a decoded Bitmap of the specified region.

关于Android图片压缩不完全加载到内存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32092928/

相关文章:

android - SQLite FTS3 模拟 LIKE somestring%

java - JMS 消息传递性能 : Lots of Topics/Queues vs. 广泛过滤(消息选择器)

android - 如何在使用改造发送到服务器之前压缩捕获的图像文件大小

performance - 循环优化。寄存器重命名如何打破依赖关系?什么是执行端口容量?

javascript - JIC - Java 图像压缩器 : Failed to execute 'drawImage' on 'CanvasRenderingContext2D' : No function was found that matched the signature

php- 压缩 base64 解码图像失败

java - 在 Android 上查找应用程序的 CPU 使用率

java - .crt 文件上出现 FileNotFoundException

java - 使用多个dex文件时是否需要将同一个包的类保存在同一个dex中

performance - 使用谷歌托管的 jQuery-ui 或自托管自定义下载的 jQuery UI?