美文网首页
bitmap图的指定大小缩放

bitmap图的指定大小缩放

作者: 伪装的狼 | 来源:发表于2020-02-08 00:13 被阅读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);
}

相关文章

网友评论

      本文标题:bitmap图的指定大小缩放

      本文链接:https://www.haomeiwen.com/subject/zhsbxhtx.html