cropiwa
cropiwa copied to clipboard
Feature/memory usage optimisation
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.
On top of image current allocations. On the bottom of image's new version allocation.
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.