bitmap图的指定大小缩放

2020-02-08  本文已影响0人  伪装的狼

//传入需要转换成的指定宽高即可。

private void resizeBitmap(float newWidth,float newHeight){
//获取原图大小
int width = bitmap.getWidth();
int height = bitmap.getHeight();

    //计算缩放比例
    float scaleWidth = newWidth/width;
    float scaleHeight = newHeight/height;

    //矩阵
    Matrix matrix = new Matrix();
    matrix.postScale(scaleWidth,scaleHeight);
    //或matrix.setScale(scaleWidth,scaleHeight);

    bitmap = Bitmap.createBitmap(bitmap,0,0,width,height,matrix,true);
}
上一篇 下一篇

猜你喜欢

热点阅读