Android 如何抓住;png错误“;使用BitmapFactory.decodeByteArray()?
我的Android应用程序中有此方法: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...
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
,位图图像如我所料为空。