android 图片压缩
来源:互联网 发布:淘宝宝贝怎么推广 编辑:程序博客网 时间:2024/06/05 10:52
/**
* 通过view的高和宽压缩
*
* @param pathName
* @param vWidth
* view的宽,0表示不压缩
* @param vHeight
* view的高,0表示不压缩
* @return
*/
public Bitmap compressBitmap(String pathName, int vWidth, int vHeight) {
BitmapFactory.Options opts = new BitmapFactory.Options();
if (vHeight > 0 && vWidth > 0) {
/**
* 计算图片的宽高
*/
opts.inJustDecodeBounds = true;
BitmapFactory.decodeFile(pathName, opts);
/**
* 压缩比例,如果小1则=1,表示不压缩 大于1,则返回原大小的1/n的图片
*/
opts.inSampleSize = Math.min(opts.outWidth / vWidth, opts.outHeight / vHeight);
/**
* 表示没有透明度
*/
opts.inPreferredConfig = Config.RGB_565;
opts.inJustDecodeBounds = false;
// opts.inPurgeable = true;
// opts.inInputShareable = true;
}
return BitmapFactory.decodeFile(pathName, opts);
}
* 通过view的高和宽压缩
*
* @param pathName
* @param vWidth
* view的宽,0表示不压缩
* @param vHeight
* view的高,0表示不压缩
* @return
*/
public Bitmap compressBitmap(String pathName, int vWidth, int vHeight) {
BitmapFactory.Options opts = new BitmapFactory.Options();
if (vHeight > 0 && vWidth > 0) {
/**
* 计算图片的宽高
*/
opts.inJustDecodeBounds = true;
BitmapFactory.decodeFile(pathName, opts);
/**
* 压缩比例,如果小1则=1,表示不压缩 大于1,则返回原大小的1/n的图片
*/
opts.inSampleSize = Math.min(opts.outWidth / vWidth, opts.outHeight / vHeight);
/**
* 表示没有透明度
*/
opts.inPreferredConfig = Config.RGB_565;
opts.inJustDecodeBounds = false;
// opts.inPurgeable = true;
// opts.inInputShareable = true;
}
return BitmapFactory.decodeFile(pathName, opts);
}
0 0
- android图片压缩方法
- android图片压缩方法
- android图片压缩
- android图片压缩
- Android图片压缩
- android图片压缩
- Android BitmapFactory 图片压缩
- android图片压缩
- android图片压缩总结
- android图片压缩一:
- Android 图片压缩二:
- Android图片压缩总结
- Android开发压缩图片
- Android图片压缩
- android 的图片压缩
- Android关于图片压缩
- android 图片压缩
- android图片压缩上传
- 进度条
- git系列------git revert
- python学习笔记--时间打印
- Service常用技巧总结
- sap abap性能优化(三)
- android 图片压缩
- Git名词解释积累
- MIDI文件(1)
- C++中string类型用于send函数-socket发送zifu
- HDU 1181
- Hadoop/Spark博客
- 1024. 科学计数法 (20)
- 学习笔记:MVC URL参数的一点小问题
- svn分支开发与主干合并(branch & merge)