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

java.io.IOException: Image failed to decode using JPEG decoder

Open Cutta opened this issue 8 years ago • 5 comments

11-05 11:08:46.154 18450-18450/fightcountdown.netvent.com.countdown E/android-crop: Error cropping image: Image failed to decode using JPEG decoder
11-05 11:08:46.154 18450-18450/fightcountdown.netvent.com.countdown E/android-crop: java.io.IOException: Image failed to decode using JPEG decoder
11-05 11:08:46.154 18450-18450/fightcountdown.netvent.com.countdown E/android-crop:     at android.graphics.BitmapRegionDecoder.nativeNewInstance(Native Method)
11-05 11:08:46.154 18450-18450/fightcountdown.netvent.com.countdown E/android-crop:     at android.graphics.BitmapRegionDecoder.newInstance(BitmapRegionDecoder.java:126)
11-05 11:08:46.154 18450-18450/fightcountdown.netvent.com.countdown E/android-crop:     at com.soundcloud.android.crop.CropImageActivity.decodeRegionCrop(CropImageActivity.java:328)
11-05 11:08:46.154 18450-18450/fightcountdown.netvent.com.countdown E/android-crop:     at com.soundcloud.android.crop.CropImageActivity.onSaveClicked(CropImageActivity.java:290)
11-05 11:08:46.154 18450-18450/fightcountdown.netvent.com.countdown E/android-crop:     at com.soundcloud.android.crop.CropImageActivity.access$000(CropImageActivity.java:45)
11-05 11:08:46.154 18450-18450/fightcountdown.netvent.com.countdown E/android-crop:     at com.soundcloud.android.crop.CropImageActivity$3.onClick(CropImageActivity.java:114)
11-05 11:08:46.154 18450-18450/fightcountdown.netvent.com.countdown E/android-crop:     at android.view.View.performClick(View.java:4247)
11-05 11:08:46.154 18450-18450/fightcountdown.netvent.com.countdown E/android-crop:     at android.view.View$PerformClick.run(View.java:17728)
11-05 11:08:46.154 18450-18450/fightcountdown.netvent.com.countdown E/android-crop:     at android.os.Handler.handleCallback(Handler.java:730)
11-05 11:08:46.154 18450-18450/fightcountdown.netvent.com.countdown E/android-crop:     at android.os.Handler.dispatchMessage(Handler.java:92)
11-05 11:08:46.154 18450-18450/fightcountdown.netvent.com.countdown E/android-crop:     at android.os.Looper.loop(Looper.java:137)
11-05 11:08:46.154 18450-18450/fightcountdown.netvent.com.countdown E/android-crop:     at android.app.ActivityThread.main(ActivityThread.java:5289)
11-05 11:08:46.154 18450-18450/fightcountdown.netvent.com.countdown E/android-crop:     at java.lang.reflect.Method.invokeNative(Native Method)
11-05 11:08:46.154 18450-18450/fightcountdown.netvent.com.countdown E/android-crop:     at java.lang.reflect.Method.invoke(Method.java:525)
11-05 11:08:46.154 18450-18450/fightcountdown.netvent.com.countdown E/android-crop:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
11-05 11:08:46.154 18450-18450/fightcountdown.netvent.com.countdown E/android-crop:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
11-05 11:08:46.154 18450-18450/fightcountdown.netvent.com.countdown E/android-crop:     at dalvik.system.NativeStart.main(Native Method)

and image is this: http://i.imgur.com/647p8ys.jpg?1

Cutta avatar Nov 05 '15 08:11 Cutta

Same here. Sounds like a JPEG and not JPG encoded.

ivanviragine avatar Jan 11 '16 19:01 ivanviragine

I have the same problem. Any solutions?

Sandrichka22 avatar Jan 21 '16 08:01 Sandrichka22

I did a little research and it seems that the BitmapRegionDecoder that this library uses to decode the cropped region has a number of problems which are caused because of the Skia library that BitmapRegionDecoder uses. The Skia library seems to has a number of unfixed bugs and although it displays the vast majority of images properly, there are numerous problems while displaying CMYK JPGs, and/or grayscale PNGs.

One possible solution, according to the creator of another library which is experiencing similar problems because of BitmapRegionDecoder, is to use a custom decoder. It would be great if this problem is solved in the future releases of this library, but frankly I don't know the complexity behind the custom decoder implementation.

Here are some useful links: https://github.com/davemorrissey/subsampling-scale-image-view/wiki/02.-Displaying-images https://github.com/davemorrissey/subsampling-scale-image-view/wiki/04.-Custom-decoders

Hope this helps

Sandrichka22 avatar Jan 21 '16 14:01 Sandrichka22

This lib is definitely not production ready. You should point this out on the main page.

ivanviragine avatar Feb 04 '16 11:02 ivanviragine

I have managed to get around this problem. BitmapFactory has no problem decoding the image, however BitmapRegionDecoder fails.

When BitmapRegionDecoder fails, I decode the full image using BitmapFactory and then compress to a temp file. Reassign the Uri and then start again.

meremammal avatar Apr 23 '16 06:04 meremammal