我是靠谱客的博主 疯狂香菇,这篇文章主要介绍SkAndroidCodec::NewFromStream returned null解决方案,现在分享给大家,希望可以做个参考。

android 7的系统上BitmapFactory.decodeStream函数第二次调用的时候会报错SkAndroidCodec::NewFromStream returned null,这是因为Android 7.0对BitmapFactory修改了BitmapFactory代码。

解决方法就是在两次decodeStream之间reset一下InputStream,增加如下的代码。


复制代码
1
2
3
4
5
try { is.reset(); } catch (IOException e) { return null; }

 于是,读取bitmap代码如下

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(79)

评论列表共有 0 条评论

立即
投稿
返回
顶部