Skip to content

Instantly share code, notes, and snippets.

@flyfire
Created November 27, 2018 09:42
Show Gist options
  • Select an option

  • Save flyfire/f90af22bb26aa6b8e3c71e8ecdec6154 to your computer and use it in GitHub Desktop.

Select an option

Save flyfire/f90af22bb26aa6b8e3c71e8ecdec6154 to your computer and use it in GitHub Desktop.
[ScaleBitmap] scale bitmap #bitmap #scale
//缩放图片大小
public Bitmap scaleBitmap(Bitmap bitmap, int newWidth, int newHeight) {
Bitmap b = bitmap;
int width = b.getWidth();
int height = b.getHeight();
// 计算缩放比例
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// 取得想要缩放的matrix参数
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
// 得到新的图片
return Bitmap.createBitmap(b, 0, 0, width, height, matrix, true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment