简体   繁体   中英

Android - Stretch canvas/bitmap to full screen width

I have a canvas in which i'm drawing a lot of bitmaps. 15x15, to be exact.

Now, what i want to do is ensure that these 15 columns of bitmaps, back to back, stretch across the entire width of the screen. But since 160/15 isn't an integer number, i can't just set the width of them to the appropriate value.

Is there any way to stretch them, or perhaps the whole canvas, to fit the screen snugly?

Thanks.

You can resize a Bitmap using a Matrix object.

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

Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);

Bitmap resized = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);

我使用canvas.scale(float scaleX,float scaleY)来制作画布及其内容,使其延伸到屏幕的宽度。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM