BitmapFactory.decodeStream 总是返回 null 并且skia 解码器显示解码返回false [英] BitmapFactory.decodeStream always returns null and skia decoder shows decode returned false
问题描述
在这里测试图像:http://images.plurk.com/tn_4134189_bf54fe418e270ce41240d534b5133884ee.gif" 我尝试了在互联网上找到的几种解决方案,但没有可行的解决方案. 我正在使用以下代码片段: 总是得到这个日志: 有什么帮助吗?谢谢. 那些解码失败的图像也不能在 试试这个作为临时解决方法: 首先添加以下类: 然后用 PlurkInputStream 包装您的原始流: 如果这对您有帮助,请告诉我. 抱歉,请尝试以下版本: 请注意,这不是高效的代码,也不是完整/正确的解决方案.它适用于大多数情况,但不是全部. test image here:
http://images.plurk.com/tn_4134189_bf54fe8e270ce41240d534b5133884ee.gif I've tried several solutions found on the internet but there is no working solution. I'm using the following snippet code: Always getting this log: Any help?
Thanks. EDIT: Those images failed to be decoded are also can not be shown on a Try this as a temporary workaround: First add the following class: Then wrap your original stream with PlurkInputStream: Let me know if this helps you. EDIT: Sorry please try the following version instead: Note that this is not efficient code nor is this a full/correct solution. It will work for most cases, but not all. 这篇关于BitmapFactory.decodeStream 总是返回 null 并且skia 解码器显示解码返回false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!Url imageUrl = new Url("http://images.plurk.com/tn_4134189_bf54fe8e270ce41240d534b5133884ee.gif");位图图像 = BitmapFactory.decodeStream(imageUrl.openStream());
DEBUG/skia(1441): --- 解码器->解码返回假
WebView
上显示.但是可以查看是否在浏览器中打开. public static class PlurkInputStream extends FilterInputStream {受保护的 PlurkInputStream(InputStream in) {超级(在);}@覆盖public int read(byte[] buffer, int offset, int count)抛出 IOException {int ret = super.read(buffer, offset, count);for ( int i = 2; i < buffer.length; i++ ) {如果(缓冲区 [i - 2] == 0x2c && 缓冲区 [i - 1] == 0x05&&缓冲区[i] == 0 ) {缓冲区[i - 1] = 0;}}返回 ret;}}
Bitmap bitmap = BitmapFactory.decodeStream(new PlurkInputStream(originalInputStream));
for ( int i = 6; i
Url imageUrl = new Url("http://images.plurk.com/tn_4134189_bf54fe8e270ce41240d534b5133884ee.gif");
Bitmap image = BitmapFactory.decodeStream(imageUrl.openStream());
DEBUG/skia(1441): --- decoder->decode returned false
WebView
. But can see if open in a Browser. 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;
}
}
Bitmap bitmap = BitmapFactory.decodeStream(new PlurkInputStream(originalInputStream));
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;
}
}
}