cropiwa icon indicating copy to clipboard operation
cropiwa copied to clipboard

Feature/memory usage optimisation

Open flasher297 opened this issue 7 years ago • 1 comments

Memory optimisation fix. In current implementation to get cropped image bitmap is uploaded to memory three times: 1st time - original imgae in tryLoadBitmap() method - by BitmapFactory.decodeStream(is, null, options); 2nd and 3rd - when we crop bitmap in applyCrop() method and whne we copy bytes from immutable cropped bitmap.

Usage of BitmapRegionDecoder allows us to load image to memory only once and in cropped size. I've tested one image with constant crop area. Current implemetation allocates ~ 112MB. BitmapRegionDecoder implementation allocates 38mb. Cropping time is slightly shorter.

memory_crop On top of image current allocations. On the bottom of image's new version allocation.

flasher297 avatar Oct 26 '17 11:10 flasher297

Hey man, thanks for the fix. Unfortunately, you have a bug there.

You call "ensureCorrectRotation" after the image was cropped, which leads to an incorrect result in case the image should have been corrected to the right rotation (you can reproduce it on Galaxy 8 for example, where the exif orientation is different than normal. You should flip the image before you crop it.

romshiri avatar Nov 09 '17 12:11 romshiri