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
How to Make Layouts for Several Android Screen Sizes
Android:Record Sound in Mp3 Format
Filling a Circle Gradually from Bottom to Top Android
How to Retrieve HTML Content from Webview (As a String)
Add Dynamic Text Over Android Seekbar Thumb
Debugging Android Ndk Native Apps
Android Button Background Color
Android Custom Layout - Ondraw() Never Gets Called
Mediaplayer Setdatasource, Better to Use Path or Filedescriptor
Cannot Deserialize Instance of Object Out of Start_Array Token in Spring Webservice
How to Use Data Binding and Kotlin in Android Studio 3.0.0
Android Volley Sending Data Twice
How to Check If Music Is Playing by Using a Broadcast Receiver
How to Force a Cache Clearing Using Universal Image Loader Android
Where Does Local.Properties Go for Android Project
How to Use Edittext Ontextchanged Event When I Press the Number