Lord_Peter
Lord_Peter

Reputation: 53

Changing the image width and height

I would like to change the height and width of the image. Displays the image using the canvas:

canvas.drawBitmap (_image, 0, 0, null);

How to change the size of the bitmap?

Upvotes: 2

Views: 1916

Answers (2)

rds
rds

Reputation: 26984

Or Bitmap.createScaledBitmap(...)

Upvotes: 1

kgiannakakis
kgiannakakis

Reputation: 104168

Use a Matrix:

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);  

Upvotes: 4

Related Questions