Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/213.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何抓住;png错误“;使用BitmapFactory.decodeByteArray()?_Android_Graphics_Error Handling_Png - Fatal编程技术网

Android 如何抓住;png错误“;使用BitmapFactory.decodeByteArray()?

Android 如何抓住;png错误“;使用BitmapFactory.decodeByteArray()?,android,graphics,error-handling,png,Android,Graphics,Error Handling,Png,我的Android应用程序中有此方法: public void displayImage(ByteArrayOutputStream pngData) { if (pngData != null) { Bitmap image = BitmapFactory.decodeByteArray(pngData.toByteArray(), 0, pngData.size()); // even when this generates a log error...

我的Android应用程序中有此方法:

public void displayImage(ByteArrayOutputStream pngData) {
    if (pngData != null) {
        Bitmap image = BitmapFactory.decodeByteArray(pngData.toByteArray(), 0, pngData.size()); // even when this generates a log error...
        if (image != null) { // ...this still evaluates true
            this.imageView.setImageBitmap(image); // ...and then this displays an all-black image
        }
    }
}
有时,
decodeByteArray
失败,控制台中会出现
D/skia:----png错误错误自适应过滤器值错误。但是,
decodeByteArray
仍然返回一个非空的图像对象。然后
setImageBitmap
显示一个空(全黑)图像


在这种情况下,我只想跳过显示图像,但我找不到测试此错误的方法。除了
image!=null
,我还尝试测试了
image.getWidth()>0
image.getByteCount()>0
image.getDensity()>0
,但它们对图像的好坏都评估为true。有没有办法捕捉到这一点?

的确,在不同的android设备上,相同的界面位图=BitmapFactory.decodeFile(“XXX.png”);将返回不同的结果。例如,对于损坏的png文件I upload(),通常移动设备将返回空位图,但Nexus 6P返回非空位图,但您无法在应用程序上预览它。

在不同的android设备上,相同的界面位图=BitmapFactory.decodeFile(“XXX.png”);将返回不同的结果。例如,对于损坏的png文件I upload(),通常移动设备将返回空位图,但Nexus 6P返回非空位图,但您无法在应用程序上预览它。

观察良好。我在安卓7的像素C上看到了
错误的自适应滤波器值
错误,但在安卓5的Nexus 10上,相同的数据触发了
解码,返回了false
,位图图像如我所料为空。观察良好。我在安卓7的像素C上看到了
错误的自适应过滤器值
错误,但在安卓5的Nexus 10上相同的数据触发了
解码,返回了false
,位图图像如我所料为空。