private static final double MAX_BITMAP_SIZE = 5e6;
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();/*
1. MAX_BITMAP_SIZE是你设置的允许的最大大小 如果宽*高小于于这个大小就不进行压缩,大于就压缩。
2.开方是因为: 如果 除完是0.81 那么 长宽各缩小为之前的0.9就可以啦 0.9*0.9=0.81
3.任意一个大于1的数,开根号后的值都是大于1的。
*/
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; }