android 下载图片出现SkImageDecoder::Factory returned null,BitmapFactory.Options压缩
2023-09-11 14:18:38 时间
网上有很多说是因为没有采用HttpClient造成的,尼玛,我改成了HttpClient 请求图片之后还是会出现SkImageDecoder::Factory returned null,
但是直接使用
bitmap = BitmapFactory.decodeStream(is); 是正常的,但解决不了图片大内存溢出的问题
解决办法:
重新获取一次流,注意看代码(红色部分):
/** * 根据网络url获取bitmap对象 * @param url * @param width 要获取的宽度 * @param height 要获取的高度 防止内存溢出 * @return */ public static Bitmap returnBitMap(String url, int width,int height) { Bitmap bitmap = null; try { HttpGet httpRequest = new HttpGet(url); Log.d("returnbitmap", "url="+url); HttpClient httpclient = new DefaultHttpClient(); HttpResponse response = (HttpResponse) httpclient.execute(httpRequest); HttpEntity entity = response.getEntity(); BufferedHttpEntity bufferedHttpEntity = new BufferedHttpEntity(entity); InputStream is = bufferedHttpEntity.getContent(); BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; //只获取图片的高宽 int scale = 1; BitmapFactory.decodeStream(is,null,options); int w = options.outWidth; int h = options.outHeight; Log.d("returnbitmap", "w="+w+";h="+h+";width="+width+";height="+height); while(true) { if ((width>0 && w < width) || (height>0 && h < height)) { break; } w /= 2; h /= 2; scale *= 2; } options.inJustDecodeBounds = false; options.inSampleSize = scale; is = bufferedHttpEntity.getContent();//重新获取流 bitmap = BitmapFactory.decodeStream(is,null,options); Log.d("returnbitmap", "bitmap="+bitmap+(bitmap==null?"bitmap is null":"bitmap is not null")); is.close(); } catch (IOException e) { e.printStackTrace(); } catch (OutOfMemoryError e) { e.printStackTrace(); } return bitmap; }
这样就可以正常下载并显示了,噢耶!!!
相关文章
- [Android]calabash-android再深入
- [Android] repo 下载Android源码(国内镜像)
- [Android Pro] Android学习——在线查看android源代码的3种方式
- Android教程-android studio 制作.9 图片
- 55、Android网络图片 加载缓存处理库的使用
- android 之断点续传详解三部曲之[二] → 断点续传下载
- Android文件Apk下载变ZIP压缩包解决方案
- Android开发学习---使用Intelij idea 13.1 进行android 开发
- 1、android源代码下载与跟踪
- android脚步---自动完成文本框
- Rockchip Android平台GPU/DDR负载变频阈值调整方法
- Android ProgressDialog 实现圆形进度对话框 和 水平进度对话框
- android stdio的自动补齐功能
- android 9.0 VolumeUI系统媒体音量设置为最大值80%
- 音视频开发(四十一):Android消息机制Native层分析
- ue5 - android 打包卡在下载gradle Downloading https://services.gradle.org/distributions/gradle-6.1.1-all.zip - 解决
- 【Android 逆向】GDA 逆向工具安装 ( GDA 下载 | GDA 简介 | 运行 GDA 分析 APK 文件 )
- 【Android 安装包优化】WebP 应用 ( libwebp 源码下载 | Android.mk 和 Application.mk 构建脚本修改 | libwebp 函数库编译 )
- 下载并在Eclipse中关联Android源代码
- 【Android】android图片轮播
- 【Android布局】在程序中设置android:gravity 和 android:layout_Gravity属性
- Android系统Camera录像过程分析
- Android 开源项目android-open-project解析之(三) ScrollView,TimeView,TipView,FlipView
- 最新Android ADT, SDK, SDK_tool等官方下载说明(及时更新)
- android include进来的组件 调用其子元素
- Android Studio 理解com.android.support:appcompat-v7:x.x.x依赖包(建议收藏)
- Android 解决之依赖包中添加的com.android.support版本不同导致冲突的问题
- Android 9.0/P(android p指安卓9.0版本) okhttp3网络请求出错