package com.js.photosdk.utils;
import android.graphics.Bitmap;
import android.graphics.Matrix;
public class ImageUtils
{
/**
* 讲图片设置为新的宽高
* @param bitmap 源图片
* @param newWidth 新的宽度
* @param newHeight 新的高度
* @return 返回重新设置宽高的图片
*/
public static Bitmap ResizeBitmap(Bitmap bitmap, int newWidth, int newHeight)
{
int width = bitmap.getWidth();
int height = bitmap.getHeight();
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height,
matrix, true);
bitmap.recycle();
return resizedBitmap;
}
}