[Java] 在Android系统中缩放图片的代码 →→→→→进入此内容的聊天室

来自 , 2019-06-03, 写在 Java, 查看 133 次.
URL http://www.code666.cn/view/6abcc8f2
  1. public static Drawable resizeImage(Bitmap bitmap, int w, int h) {
  2.  
  3.                 // load the origial Bitmap
  4.                 Bitmap BitmapOrg = bitmap;
  5.  
  6.                 int width = BitmapOrg.getWidth();
  7.                 int height = BitmapOrg.getHeight();
  8.                 int newWidth = w;
  9.                 int newHeight = h;
  10.  
  11.                 // calculate the scale
  12.                 float scaleWidth = ((float) newWidth) / width;
  13.                 float scaleHeight = ((float) newHeight) / height;
  14.  
  15.                 // create a matrix for the manipulation
  16.                 Matrix matrix = new Matrix();
  17.                 // resize the Bitmap
  18.                 matrix.postScale(scaleWidth, scaleHeight);
  19.                 // if you want to rotate the Bitmap
  20.                 // matrix.postRotate(45);
  21.  
  22.                 // recreate the new Bitmap
  23.                 Bitmap resizedBitmap = Bitmap.createBitmap(BitmapOrg, 0, 0, width,
  24.                                 height, matrix, true);
  25.  
  26.                 // make a Drawable from Bitmap to allow to set the Bitmap
  27.                 // to the ImageView, ImageButton or what ever
  28.                 return new BitmapDrawable(resizedBitmap);
  29.  
  30.         }
  31. //java/6370

回复 "在Android系统中缩放图片的代码"

这儿你可以回复上面这条便签

captcha