更改图像宽度和高度

时间:2010-11-17 14:37:34

标签: java android image bitmap

我想改变图像的高度和宽度。使用canvas

显示图像
canvas.drawBitmap (_image, 0, 0, null);

如何更改位图的大小?

2 个答案:

答案 0 :(得分:4)

使用矩阵:

int width = bitmap.getWidth();
int height = bitmap.getHeight();

float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;      

matrix = new Matrix();

matrix.postScale(scaleWidth, scaleHeight);

Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0,
                    width, height, matrix, true);  

答案 1 :(得分:1)

Bitmap.createScaledBitmap(...)