/**
* 通过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);
}