Is there any way to increase the width (or height) of a Bitmap without stretching it? Basically, I have a 200×100 bitmap and I want to make it square (200×200) by appending 50 (white / transparent) pixels to the left and 50 pixels to the right.
I don’t want to draw this Bitmap on the screen so, ideally, I should be using a transformation Matrix in a “smart” way or something like that, but I just can’t figure it out…
You may try something like this:
Note: The black border is not part of the image. I chose dark red as a background color to see the actual size of the image and to distinguish it from black and the source image’s color (which is always painted centered).
By drawing it on a Canvas it is not visible on the screen. I used an ImageView just to test the code.
Here is the output I get for w=200,h=100:
Here is the output I get for w=100,h=200: