有什么方法可以在不将图像完全加载到内存的情况下压缩图像?
据我了解 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/