0

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.

Image 1:

  • Works: Yes
  • ffprobe: Stream #0:0: Video: png, rgba, 100x100
  • Size: 5816 bytes

Image 2:

  • 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

Image 3:

  • Works: Yes
  • ffprobe: Stream #0:0: Video: png, rgb24, 175x175
  • Size: 2589 bytes
Community
  • 1
  • 1
Knossos
  • 15,802
  • 10
  • 54
  • 91
  • Looks like image 2 is corrupted or the android png parser has some bugs. If you have the original I'd try regenerating the png in photoshop. – Gabe Sechan Mar 21 '14 at 16:27

1 Answers1

0

can you try this:

 inSampleSize = 2;

or can you look at this : BitmapFactory.decodeStream always returns null and skia decoder shows decode returned false

I think the size is the problem.

Community
  • 1
  • 1
CompEng
  • 7,161
  • 16
  • 68
  • 122
  • I have previously downsampled the picture by: options.inSampleSize = 4; With no change. – Knossos Mar 21 '14 at 16:34
  • can you try firstly the second image – CompEng Mar 21 '14 at 16:36
  • I re-ran the test. With the same result. inSampleSize = 2; No change. inSampleSize = 4; No change. When it is applied to all images, 1 & 3 are vastly reduced in size (as expected). – Knossos Mar 21 '14 at 16:38
  • can you try this : **http://stackoverflow.com/questions/20636425/image-reading-error** – CompEng Mar 21 '14 at 17:05
  • The image location is : "/data/data/packagename/cache/mailbox/23.test1.png". It should be fine for access. If it wasn't then it wouldn't load any images. – Knossos Mar 24 '14 at 08:10
  • http://stackoverflow.com/questions/3802820/bitmapfactory-decodestream-always-returns-null-and-skia-decoder-shows-decode-ret can you look at this – CompEng Mar 24 '14 at 09:03
  • I already investigated that link. It is even in my original post (albeit not very visible) – Knossos Mar 24 '14 at 09:09
  • can you replace different image with same name with **image2** because I want to know is the image is problem or code? – CompEng Mar 24 '14 at 09:17
  • File name makes no difference to the result. The files also have permissions: -rw-r--r-- – Knossos Mar 24 '14 at 11:18
  • I mean please put different image instead of image 2 with same name , so maybe it does not give error (maybe the problem is image?) – CompEng Mar 24 '14 at 11:35