itmap icon = null;//原始图片
int width = icon.getWidth(), height = icon.getHeight();
float scaleRate = 0.8f;//缩小的比例
while(width >= 300 || width >= 300) {
Matrix matrix = new Matrix();
matrix.postScale(width * scaleRate, height * scaleRate);
// 得到新的图片
Bitmap newIcon = Bitmap.createBitmap(icon, 0, 0, width, height, matrix, true);
icon.recycle();
icon = newIcon;
width = icon.getWidth(), height = icon.getHeight();
}int width = icon.getWidth(), height = icon.getHeight();
if(width > 300 || width > 300) {
float scaleRate = width > height ? 300 / width : 300 / height;
Matrix matrix = new Matrix();
matrix.postScale(width * scaleRate, height * scaleRate);
// 得到新的图片
Bitmap newIcon = Bitmap.createBitmap(icon, 0, 0, width, height, matrix, true);
icon.recycle();
icon = newIcon;
}
取消
评论