android-crop
android-crop copied to clipboard
Fix certain JPEG files are failed to be decoded with BitmapRegionDecoder
- this is a known issue of Google : https://code.google.com/p/android/issues/detail?id=77195
- this should fix issue #177
Tested on certain files and it worked! Thanks!
@ivanviragine glad to know that! thanks for your response
Unfortunately, this isn't working. Some pictures are getting "y + height must be <= bitmap.height()" exception. I will dig in to understand the problem, but sounds like it's a width and height rounding problem...
Here's what I've got so far:
original photo: 4128 x 2322
crop should be (squared example): 2322 x 2322
so, the rectangle should be left = 903 (that is imageWidth-cropWidth / 2), right = 3225 (that is left+cropWidth), top = 0, bottom = 2322 (that is cropHeight)
Ok?
The code is generating these values instead: left = 900 (-3 of actual value), right = 3224 (-1 of actual value), top = 0, bottom = 2324 (+2 of actual value) These values are coming from cropRect var, which holds these values: left = 225, right = 806, top = 0, bottom = 581.
But, somehow,
croppedImage = decoder.decodeRegion(rect, new BitmapFactory.Options());
finds its way, even with these wrong parameters (like 2324 as height instead of the actual 2322 height), but
croppedImage = Bitmap.createBitmap(croppedImage, rect.left, rect.top, rect.width(), rect.height());
doesn't.
@ivanviragine May you provide your tested picture in this case so I can reproduce the issue and take a deeper look. Thanks.