Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android picture compression without loading fully into memory

Is there any way to compress image without fully loading it into memory? As I understand BitmapFactory.decodeStream and similar methods load everything in memory and only after loading entire picture it can be compressed via Bitmap.compress

My task is to send picture from android to server

like image 583
Art Avatar asked Aug 19 '15 10:08

Art


1 Answers

You could use a BitmapRegionDecoder to read only a part of the original image, then compress and upload each part separately.

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.

like image 66
bwt Avatar answered Sep 28 '22 20:09

bwt