关于异常:SkImageDecoder::Factory returned null
来源:互联网 发布:被收购的中国品牌 知乎 编辑:程序博客网 时间:2024/04/30 15:41
开发中遇到一个问题:
04-07 23:51:59.590: D/skia(7827): --- SkImageDecoder::Factory returned null
本来是下载一大批图片的,可是遇到了这个问题,图片没下载下来,
上网搜了一下,发现都是讲“是HttpURLConnection的问题,如果使用apache的HttpClient的话,就不会有问题了”
我一看,也以为是的,毕竟我也用了Java的HttpURLConnection,改了之后发现问题依然存在,恶心了一把。妹的,
只有一步步调试了,后来发现是图片压缩时的问题:BitmapFactory.decodeStream(is, null, opts);
就在这一步出了错,妹的,其他地方时这个地方就不会出错,怎么这个时候这地方出错了呢?
怎么这么恶心呢,,
明天继续调,,
现在是根据返回的bitmap去压缩图片,
code:
Bitmap bitmap = BitmapFactory.decodeStream(i, null, opt);Matrix matrix = new Matrix(); matrix.postScale(0.5f,0.5f); //长和宽放大缩小的比例Bitmap resizeBmp = Bitmap.createBitmap(bitmap,0,0,bitmap.getWidth(),bitmap.getHeight(),matrix,true);return resizeBmp;看这个错误的提示: SkImageDecoder::Factory returned null,想来是BitmapFactory的问题,找到decodeStream代码:
/** * Decode an input stream into a bitmap. If the input stream is null, or * cannot be used to decode a bitmap, the function returns null. * The stream's position will be where ever it was after the encoded data * was read. * * @param is The input stream that holds the raw data to be decoded into a * bitmap. * @param outPadding If not null, return the padding rect for the bitmap if * it exists, otherwise set padding to [-1,-1,-1,-1]. If * no bitmap is returned (null) then padding is * unchanged. * @param opts null-ok; Options that control downsampling and whether the * image should be completely decoded, or just is size returned. * @return The decoded bitmap, or null if the image data could not be * decoded, or, if opts is non-null, if opts requested only the * size be returned (in opts.outWidth and opts.outHeight) */ public static Bitmap decodeStream(InputStream is, Rect outPadding, Options opts) { // we don't throw in this case, thus allowing the caller to only check // the cache, and not force the image to be decoded. if (is == null) { return null; } // we need mark/reset to work properly if (!is.markSupported()) { is = new BufferedInputStream(is, DECODE_BUFFER_SIZE); } // so we can call reset() if a given codec gives up after reading up to // this many bytes. FIXME: need to find out from the codecs what this // value should be. is.mark(1024); Bitmap bm; boolean finish = true; if (is instanceof AssetManager.AssetInputStream) { final int asset = ((AssetManager.AssetInputStream) is).getAssetInt(); if (opts == null || (opts.inScaled && opts.inBitmap == null)) { float scale = 1.0f; int targetDensity = 0; if (opts != null) { final int density = opts.inDensity; targetDensity = opts.inTargetDensity; if (density != 0 && targetDensity != 0) { scale = targetDensity / (float) density; } } bm = nativeDecodeAsset(asset, outPadding, opts, true, scale); if (bm != null && targetDensity != 0) bm.setDensity(targetDensity); finish = false; } else { bm = nativeDecodeAsset(asset, outPadding, opts); } } else { // pass some temp storage down to the native code. 1024 is made up, // but should be large enough to avoid too many small calls back // into is.read(...) This number is not related to the value passed // to mark(...) above. byte [] tempStorage = null; if (opts != null) tempStorage = opts.inTempStorage; if (tempStorage == null) tempStorage = new byte[16 * 1024]; if (opts == null || (opts.inScaled && opts.inBitmap == null)) { float scale = 1.0f; int targetDensity = 0; if (opts != null) { final int density = opts.inDensity; targetDensity = opts.inTargetDensity; if (density != 0 && targetDensity != 0) { scale = targetDensity / (float) density; } } bm = nativeDecodeStream(is, tempStorage, outPadding, opts, true, scale); if (bm != null && targetDensity != 0) bm.setDensity(targetDensity); finish = false; } else { bm = nativeDecodeStream(is, tempStorage, outPadding, opts); } } if (bm == null && opts != null && opts.inBitmap != null) { throw new IllegalArgumentException("Problem decoding into existing bitmap"); } return finish ? finishDecode(bm, outPadding, opts) : bm; }
其中的注释说明:
若图片数据不可被decoded,则返回空:“The decoded bitmap, or null if the image data could not be decoded”
应该是这个流不能被decoded,所以BitmapFactory.decodeSteam时返回null,但为什么不能被decode呢?
在这个BitmapFacotry中也没找到有关“SkImageDecoder::Factory returned null”的字符,在系统源码中找到文件:SkImageDecoder.cpp
其中:
bool SkImageDecoder::DecodeStream(SkStream* stream, SkBitmap* bm, SkBitmap::Config pref, Mode mode, Format* format) { SkASSERT(stream); SkASSERT(bm); bool success = false; SkImageDecoder* codec = SkImageDecoder::Factory(stream); if (NULL != codec) { success = codec->decode(stream, bm, pref, mode); if (success && format) { *format = codec->getFormat(); } delete codec; } return success;}
在这里假如codec为空,则返回的success为false,然后系统哪里会根据这个返回值来提示那句提示呢?
先做项目,以后再解决这个问题。。
- 关于异常:SkImageDecoder::Factory returned null
- SkImageDecoder::Factory returned null
- SkImageDecoder::Factory returned null
- SkImageDecoder::Factory returned null
- SkImageDecoder::Factory returned null
- SkImageDecoder::Factory returned null
- Android SkImageDecoder::Factory returned null
- Android: SkImageDecoder:: Factory returned null
- skia : --- SkImageDecoder::Factory returned null
- skia : --- SkImageDecoder::Factory returned null
- Android加载图片出现SKImagedecoder::Factory returned null 该怎么解决
- 读取网络图片和本地sd卡图片文件 解析为空 SkImageDecoder::Factory returned null
- BitmapFactory.decodeStream。报错:SkImageDecoder::Factory returned null 原因及解决方法
- 王立平--AES加密图片实现 SkImageDecoder::Factory return null
- 关于Expected one result (or null) to be returned by selectOne(), but found: 3。。。。异常
- findLibrary returned null
- OracleADF报javax.el.PropertyNotFoundException: Target Unreachable, 'ManagedBean' returned null 异常
- 【异常】百度定位sdk Couldn't load locSDK3 from loader dalvik findLibrary returned null
- 《自动控制原理》(胥布工版)习题3-4(使用GUI)
- 传送门 (持续更新中,汇总自其他博客)
- 我的地盘我做主
- Android 常用RGB值以及中英文名称
- [Firefox插件]Google搜索提速插件推荐
- 关于异常:SkImageDecoder::Factory returned null
- 进程间通讯
- 虚函数表是在编译的时候还是运行的时候产生的
- 动态规划之背包01
- 日期函数months_between的用法
- Cocos2dx 3.0 过渡篇(二十三) C++11一种新随机数获取方法
- 02.黑马程序员-关键字、标示符、注释
- 吹水新闻上线,欢迎前踩一脚增加服务器压力
- 使用 Python 编写套接字应用程序 套接字和 SocketServer 模块