Android图片压缩学习
来源:互联网 发布:淘宝优惠券小程序 编辑:程序博客网 时间:2024/06/14 05:28
Android图片压缩学习
很多情况下需要对一张分辨率特别高的图片进行压缩,
不然会导致在很小的控件上使用了一张非常大分辨率的图片而OOM
在BItmapFactory.Options中设置inSampleSize的值,比如一个20148X1536的图片, inSampleSize设置为4,那么会产出一个512X384大小的bitmap
获取图片大小
public int calculateInSampleSize( BitmapFactory.Options options,int reqWidth, int reqHeight ){ final int height = options.outHeight; final int width = options.outWidth; int inSampleSize = 1; if(height > reqHeight || width > reqWidth){ final int halfHeight = height/2; final int halfWidth = width/2; while ((halfHeight / inSampleSize) > reqHeight || (halfWidth / inSampleSize) > reqWidth) { inSampleSize *= 2; } } return inSampleSize; }
加载图片压缩图片
public Bitmap decodeSampledBitmapFormResoure(int res,int reqWidth,int reqHeight){ final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeResource(getResources(),res,options); options.inSampleSize = calculateInSampleSize(options,reqWidth,reqHeight); options.inJustDecodeBounds = false; return BitmapFactory.decodeResource(getResources(),res,options); }
这样就可以加载简单的图片并且压缩
0 0
- Android图片压缩学习
- android图片压缩方法
- android图片压缩方法
- android图片压缩
- android图片压缩
- Android图片压缩
- android图片压缩
- Android BitmapFactory 图片压缩
- android图片压缩
- android图片压缩总结
- android图片压缩一:
- Android 图片压缩二:
- Android图片压缩总结
- Android开发压缩图片
- Android图片压缩
- android 的图片压缩
- Android关于图片压缩
- android 图片压缩
- 我是一个网卡
- mysql的alter命令
- linux技巧
- 读《携程异步消息系统实践》之总结
- csdn待改进点之13------>每次评论博文, 平均约5s才有显示成功, 请不要跟我说这是网络问题
- Android图片压缩学习
- leetcode #103 in cpp
- TextView实现跑马灯效果
- UI控件的公共属性
- 谈谈对Spring IOC的理解
- 桶排序
- 系统权限进入mysql数据库看不到自己建立的数据库的解决办法
- 匹配包含换行符(回车)的任意字符串的正则表达式
- Android Studio建立jni开发环境