android 7的系统上BitmapFactory.decodeStream函数第二次调用的时候会报错SkAndroidCodec::NewFromStream returned null,这是因为Android 7.0对BitmapFactory修改了BitmapFactory代码。
解决方法就是在两次decodeStream之间reset一下InputStream,增加如下的代码。
try {
is.reset();
} catch (IOException e) {
return null;
}
于是,读取bitmap代码如下
private Bitmap getImage(String imagename) { // Log.dd(logger, "AsyncImageLoader: " + ORDNER_IMAGES + imagename); AssetManager asset = context.getAssets(); InputStream is = null; try { is = asset.open(ORDNER_IMAGES + imagename); } catch (IOException e) { // Log.de(logger, "image konnte nicht gelesen werden: " + ORDNER_IMAGES + imagename); return null; } // First decode with inJustDecodeBounds=true to check dimensions final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeStream(is, null, options);
try { is.reset(); } catch (IOException e) { }// Calculate inSampleSize options.inSampleSize = calculateInSampleSize(options, PW, PH); // Decode bitmap with inSampleSize set options.inJustDecodeBounds = false; // Lesen des Bitmaps in der optimierten Groesse return BitmapFactory.decodeStream(is, null, options);}
来源:
https://stackoverflow.com/questions/39316069/bitmapfactory-decodestream-from-assets-returns-null-on-android-7
最后
以上就是疯狂香菇最近收集整理的关于SkAndroidCodec::NewFromStream returned null解决方案的全部内容,更多相关SkAndroidCodec::NewFromStream内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复