概述
Bitmap压缩用到的场景:{
1.移动端上传文件需要对本地拍摄保存的文件压缩:图片的缩放比例换算 大小的压缩
2.加载本地图片显示View位图所需要的图片大小并没有那么大
3.图片缓存:请求服务器上的资源缓存到内存或者本地存储提高缓存加载速率
}
Bitmap缓存的优点:1.减少内存开销读取和存储更快 2.提高App流畅度
1.采样率压缩:
BitmapFactory.Options options = new BitmapFactory.Options(); //获取Bitmap工厂类
options.inJustDecodeBounds = true; //true 只返回Bitmap宽高 false 返回Bitmap对象实体
BitmapFactory.decodeFile(fileUrl, options);
int width = options.outWidth;
int height = options.outHeight;
int inSampleSize = 1; //采样率:采样率以1/2++ 形式换算
//根据输入的宽高换算采样率
if (height > outHeight || width > outWith) {
final int halfHeight = height / 2;
final int halfWidth = width / 2;
while ((halfHeight / inSampleSize) >= outHeight &&
(halfWidth / inSampleSize) >= outWith)
最后
以上就是洁净睫毛为你收集整理的android之获取本地图片并压缩方法,Android Bitmap 几种常见的压缩方式总结的全部内容,希望文章能够帮你解决android之获取本地图片并压缩方法,Android Bitmap 几种常见的压缩方式总结所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复