private static final double MAX_BITMAP_SIZE = 5e6; spa
private String handleChoosedPicture(Bitmap bitmap,String path) {
if(bitmap == null || bitmap.isRecycled()){
return "";
}
if(DEBUG){
Log.d(TAG, "handleChoosedPicture path : " + path);
}
int w = bitmap.getWidth();
int h = bitmap.getHeight();get
/*it
1. MAX_BITMAP_SIZE是你設置的容許的最大大小 若是寬*高小於於這個大小就不進行壓縮,大於就壓縮。io
2.開方是由於: 若是 除完是0.81 那麼 長寬各縮小爲以前的0.9就能夠啦 0.9*0.9=0.81sed
3.任意一個大於1的數,開根號後的值都是大於1的。map
*/
float ratio = (float) Math.sqrt(MAX_BITMAP_SIZE/(w*h));
if(DEBUG){
Log.d(TAG, "handleChoosedPicture ratio = " + ratio);
}
ratio = ratio > 1 ? 1 : ratio;
int degree = mImageRotate == 0 ? BitmapUtil.readPictureDegree(path) : mImageRotate;
if(DEBUG){
Log.d(TAG, "handleChoosedPicture degree = " + degree);
}
bitmap = BitmapUtil.rotateAndScaleImageView(degree, bitmap, ratio);
String resultPath = FileUtil.genPath();
BitmapUtil.saveBitmap(resultPath, bitmap);
return resultPath;
}float