This appears to be a common issue here in Stackoverflow, most appear to be errors relating to this bug. However, I think mine is different. I am loading my image from the internal storage, so it should not have download time issues that cause the aforementioned bug.
This is some stripped down code that I use to fill the ImageView with the file.
Options opts = new Options();
opts.inSampleSize = 1;
opts.inPurgeable = true;
opts.inInputShareable = true;
opts.inTempStorage = new byte[32 * 1024];
Bitmap bm = null;
try {
// Use BufferedInputStream to attempt to alleviate null bitmap errors. This is/used to be an [Android bug.
bm = BitmapFactory.decodeStream(new BufferedInputStream(new FileInputStream(imageFile)), null, opts);
} catch (OutOfMemoryError e) {
// File is probably too big, try down-sampling
} catch (FileNotFoundException e) {
// The input File was not found
}
if(bm != null) {
imageView.setImageBitmap(bm);
} else {
// Give a warning
}
This works with some of my files, and not with others. I have uploaded the images I am testing with. I made all 3 with pre-existing filters from GIMP. None of the files give me OutOfMemory errors.
- Works: Yes
- ffprobe: Stream #0:0: Video: png, rgba, 100x100
- Size: 5816 bytes
- Works: No
- ffprobe: Stream #0:0: Video: png, rgba, 200x200
- Size: 48781 bytes
Received in logcat:
D/skia(16422): ------ png error Read Error!
D/skia(16422): --- decoder->decode returned false
- Works: Yes
- ffprobe: Stream #0:0: Video: png, rgb24, 175x175
- Size: 2589 bytes