【发布时间】:2013-08-14 11:40:56
【问题描述】:
我目前有一个解码位图的方法来优化图像文件的大小,但是输入文件不会是位图,然后会解码为位图。所以我的问题是,如果我的输入已经是位图,我该如何调整它的大小?谢谢。
private Bitmap compressFile(File f) {
int REQUIRED_SIZE = 80;
try {
// decode image size
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeStream(new FileInputStream(f), null, o);
// Find the correct scale value. It should be the power of 2.
int width_tmp = o.outWidth;// , height_tmp = o.outHeight;
int scale = 1;
while (REQUIRED_SIZE > 0) {
if (width_tmp <= REQUIRED_SIZE)
break;
width_tmp /= 2;
// height_tmp /= 2;
scale++;
}
// decode with inSampleSize
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize = scale;
return BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
} catch (FileNotFoundException e) {
}
return null;
}
我想改成的是compressFile (Bitmap f)
【问题讨论】:
-
你是从网上加载图片还是从图库中选择?
标签: android decode bitmapimage bitmapfactory