bitmap 压缩图片
2014年02月01日
⁄ 综合
⁄ 共 1053字 ⁄ 字号
小 中 大
-
BitmapFactory.Options opt = new BitmapFactory.Options();
-
-
opt.inJustDecodeBounds = true;
-
bm = BitmapFactory.decodeFile(absolutePath, opt);
-
-
-
int picWidth = opt.outWidth;
-
int picHeight = opt.outHeight;
-
-
-
WindowManager windowManager = getWindowManager();
-
Display display = windowManager.getDefaultDisplay();
-
int screenWidth = display.getWidth();
-
int screenHeight = display.getHeight();
-
-
-
opt.inSampleSize = 1;
-
-
if(picWidth > picHeight){
-
if(picWidth > screenWidth)
-
opt.inSampleSize = picWidth/screenWidth;
-
}
-
else{
-
if(picHeight > screenHeight)
-
-
opt.inSampleSize = picHeight/screenHeight;
-
}
-
-
-
opt.inJustDecodeBounds = false;
-
bm = BitmapFactory.decodeFile(absolutePath, opt);
-
-
-
iv.setImageBitmap(bm);