读取网络图片和本地sd卡图片文件 解析为空 SkImageDecoder::Factory returned null
来源:互联网 发布:安卓pad应用推荐 知乎 编辑:程序博客网 时间:2024/05/01 19:53
1.sd卡读取图片解析返回null对象(图片实际是存在的sd卡)
最近在使用BitmapFactory.decodeByteArray读取本地图片有时会发生读取的图片是null(联想手机一些横拍照片),保存在本地后,通过字节流读取图片文件再转换为图片,可能会的报SkImageDecoder::Factory returned null的log日志导致解析不成功返回null对象
解决方法:BitmapFactory.decodeFile(picfileString,opts)代替上面方法直接根据地址读取转换为图片不再出现空!
2.网络读取字节流转换图片返回null对象(读取的字节流长度是有的)
错误方法:
BitmapFactory.decodeStream(conn.getInputStream());直接把网络数据流转换成图片(图片大小有限制,大图可能出现解析不成功返回为null)
BitmapFactory.decodeByteArray();把conn.getInputStream()转换成字节流作为参数传入解析成图片也可能会出现空
解决方法:把网络数据流转换文件,存储在本地再通过BitmapFactory.decodeFile(picfileString,opts)读取!
/ /把图片存到本地 File file=new File(path); InputStream inputStream=conn.getInputStream(); FileOutputStream outputSteam=new FileOutputStream(file); byte[] buffer=new byte[2048]; int readbyte=0; while((readbyte=inputStream.read(buffer))!=-1) { outputSteam.write(buffer, 0, readbyte); }outputSteam.close();inputStream.close(); //读取图片 BitmapFactory.Options opts = new BitmapFactory.Options(); int scale=1;//默认缩放比例,1代表不缩放 opts.inJustDecodeBounds = true ;//不获取图片,只是拿到图片信息 Bitmap bitmap=BitmapFactory.decodeFile(picPath opts); int w = opts.outWidth; int h = opts.outHeight; //计算长宽缩放比例(这里120表示要显示的长宽) double scalew=opts.outWidth/120.0; double scaleh=opts.outHeight/120.0; scale=(int)Math.sqrt(Double.valueOf((scalew*scalew+scaleh*scaleh))); if(scale==0){scale=1;}else{//取2的倍数缩放if(scale%2==0){}else{scale=scale+1;}} opts.inJustDecodeBounds = false ;//确认缩放比例后开始准备加载合适的缩放比图片 opts.inSampleSize = scale; opts.inPreferredConfig=Config.RGB_565; //bitmap=BitmapFactory.decodeByteArray(b, 0, b.length, opts); bitmap=BitmapFactory.decodeFile(MyUtils.getTempPic()+clipPicName, opts);
0 0
- 读取网络图片和本地sd卡图片文件 解析为空 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 该怎么解决
- 关于异常:SkImageDecoder::Factory returned null
- 王立平--AES加密图片实现 SkImageDecoder::Factory return null
- 解决 读取sd卡图片,判断Bitmap 为null
- Android 读取本地(SD卡)图片
- Android 读取本地(SD卡)图片
- 读取本地(SD卡)图片转为Bitmap
- Android 读取本地(SD卡)图片
- Android 中 RegistrantList消息处理机制 以android 5.0 MT为例
- struts2 spring集成时struts.xml文件中action的class属性值意义
- git常用命令
- Visual Attention
- 友盟消息推送SDK集成
- 读取网络图片和本地sd卡图片文件 解析为空 SkImageDecoder::Factory returned null
- 数列分段
- Binary Search Tree Iterator
- C++定义的时钟类(主要是类的定义、数据成员、成员函数的定义,类对象的定义及对象之间的赋值的简单例子)
- Java - JDBC
- Centos以rpm形式安装mysql
- 蓝桥杯-入门训练-圆的面积
- 浏览器首页被劫持为http://hao.169x.cn/的修复方法
- 大端小端