This is the code I'm using:
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 8;
Bitmap imatgeOriginal = BitmapFactory.decodeFile(imageUrl, options);
Bitmap resizedbitmap = Bitmap.createScaledBitmap(imatgeOriginal, 1000, 1000, true);
As you can see I resize the image with the Options, but anyways it just crashes on the last line, throwing a NullPointerException. So imatgeOriginal
is null
Why is this happening?
Some notes:
- The image is 2 MB (less than the 16 MB limit) and the size is 1105 × 1491
- The image does exist
- The same code works with images smaller than 1.5 MB
Output in logcat:
08-22 15:11:13.249: E/AndroidRuntime(5404): FATAL EXCEPTION: main
08-22 15:11:13.249: E/AndroidRuntime(5404):
java.lang.NullPointerException 08-22 15:11:13.249:
E/AndroidRuntime(5404): at
android.graphics.Bitmap.createScaledBitmap(Bitmap.java:432) 08-22
15:11:13.249: E/AndroidRuntime(5404): at
myclass.onAnimationEnd(productView.java:2126) 08-22 15:11:13.249:
E/AndroidRuntime(5404): at
android.view.animation.AnimationSet.getTransformation(AnimationSet.java:397)
Edit:
Something weird is happening, the File Image exists, the route is correct. However android detects this image as CORRUPT or atleast it can't be opened with any tool available (Default gallery, file explorer, no my app). However, if I download the image to my computer, the image is displayed perfectly. This app is also run in iOS and the same image is actually visible there and looking not corrupt.
So I guess there's some limitations in Android to load JPEG files.
Did you guys have any problem similar like this?
Some resources I've found: http://code.google.com/p/skia/issues/detail?id=69#c2 Unable to load JPEG-image with BitmapFactory.decodeFile. Returns null