android-crop icon indicating copy to clipboard operation
android-crop copied to clipboard

Fix certain JPEG files are failed to be decoded with BitmapRegionDecoder

Open amliu opened this issue 8 years ago • 5 comments

  • this is a known issue of Google : https://code.google.com/p/android/issues/detail?id=77195
  • this should fix issue #177

amliu avatar Apr 11 '16 15:04 amliu

Tested on certain files and it worked! Thanks!

ivanviragine avatar Jun 22 '16 12:06 ivanviragine

@ivanviragine glad to know that! thanks for your response

amliu avatar Jun 30 '16 05:06 amliu

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...

ivanviragine avatar Jul 14 '16 19:07 ivanviragine

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 avatar Jul 14 '16 19:07 ivanviragine

@ivanviragine May you provide your tested picture in this case so I can reproduce the issue and take a deeper look. Thanks.

amliu avatar Jul 15 '16 02:07 amliu