Android Decoder->Decode Returned False for Bitmap Download

skia decoder-decode returned false when download image and display in imageview

Try this,

String strPicture;
for (int i = 0; i < address.length(); i++) {
JSONObject c = address.getJSONObject(i);
strPicture= c.getString(TAG_IMAGE);
byte bytePic[] = null;
try {
bytePic = Base64.decode(strPicture, Base64.DEFAULT);
} catch (Exception e) {
e.printStackTrace();
}

if (bytePic != null) {
ByteArrayInputStream imageStream = new ByteArrayInputStream(
bytePic);
Bitmap theImage = BitmapFactory.decodeStream(imageStream);
imageStream.reset();
imageView.setImageBitmap(theImage); //Setting image to the image view
}
}

decoder-decode returned false when download image and view it in ImageView

This is the problems of image.

BitmapFactory.decodeStream always returns null and skia decoder shows decode returned false

Try this as a temporary workaround:

First add the following class:

  public static class PlurkInputStream extends FilterInputStream {

protected PlurkInputStream(InputStream in) {
super(in);
}

@Override
public int read(byte[] buffer, int offset, int count)
throws IOException {
int ret = super.read(buffer, offset, count);
for ( int i = 2; i < buffer.length; i++ ) {
if ( buffer[i - 2] == 0x2c && buffer[i - 1] == 0x05
&& buffer[i] == 0 ) {
buffer[i - 1] = 0;
}
}
return ret;
}

}

Then wrap your original stream with PlurkInputStream:

Bitmap bitmap = BitmapFactory.decodeStream(new PlurkInputStream(originalInputStream));

Let me know if this helps you.

EDIT:

Sorry please try the following version instead:

        for ( int i = 6; i < buffer.length - 4; i++ ) {
if ( buffer[i] == 0x2c ) {
if ( buffer[i + 2] == 0 && buffer[i + 1] > 0
&& buffer[i + 1] <= 48 ) {
buffer[i + 1] = 0;
}
if ( buffer[i + 4] == 0 && buffer[i + 3] > 0
&& buffer[i + 3] <= 48 ) {
buffer[i + 3] = 0;
}
}
}

Note that this is not efficient code nor is this a full/correct solution. It will work for most cases, but not all.

BitmapFactory.decodeFile returns null with a proper file

I've solved this by adding a while loop with an if else

The following code:

    BitmapFactory.Options opt = new BitmapFactory.Options();
opt.inDither = true;
opt.inPreferredConfig = Bitmap.Config.ARGB_8888;

int i = 0;
while (canvasBitmap == null && ++i < 99) {

System.gc();

Log.d(TAG, "Trying again: " + i);
canvasBitmap = BitmapFactory.decodeFile(myFile.getAbsolutePath(), opt);
}

It seems to be quite inefficient but works, I'm also running it outside main thread so it's not gonna cause any not responsive behavior.



Related Topics



Leave a reply



Submit