您的位置:首页 > 其它

skia : --- SkImageDecoder::Factory returned null

2016-04-27 21:16 459 查看
转载自:/article/10916304.html

写一个从uri load图片到imageView的功能,在从uri读取文件进行重新decode的时候出现了这个错误,困惑了半天,发现原来是inputStream引起的

public static Bitmap decodeUri(Context context, Uri uri, int reqWidth, int reqHeight) {
InputStream input = null;
Bitmap bitmap = null;
try {
input = context.getContentResolver().openInputStream(uri);
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeStream(input, null, o);
input.close();
input = null;

o.inSampleSize = calculateInSampleSize(o, reqWidth, reqHeight);

// Decode bitmap with inSampleSize set
o.inJustDecodeBounds = false;
input = context.getContentResolver().openInputStream(uri);// 这个地方需要重新获取inputstream,不然就会出现如上错
bitmap = BitmapFactory.decodeStream(input, null, o);
input.close();
input = null;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
try {
if(input != null) {
input.close();
}
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
return bitmap;
}


网上有说inputStream.markSupported() 和 inputStream.reset() 搭配使用解决的,但是我没有成功。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: