简体   繁体   English

Android Canvas.scale()而非四舍五入

[英]Android Canvas.scale() and not rounded numbers

I'm scaling some bitmaps in canvas and I have some problems. 我正在缩放画布中的某些位图,但遇到了一些问题。 I have this image 640x360 and want to fill it to the screen. 我有此图像640x360,并希望将其填充到屏幕上。 My screen is 1196x720px so I have to scale the image by 1.86875 x 2.0 times. 我的屏幕是1196x720px,所以我必须将图像缩放1.86875 x 2.0倍。

The code is this: 代码是这样的:

canvas.save(Canvas.MATRIX_SAVE_FLAG);
canvas.scale((float)(1.86875), (float)(2.0),0,0);
canvas.drawBitmap(this.backgroundMap, 0, 0, null);
canvas.restore();

The image is scaling correctly in axis Y but it's wrong of, I think 100 pixels in X axis. 图像在Y轴上正确缩放,但是这是错误的,我认为X轴为100像素。 Any idea on how I can resolve this? 关于如何解决此问题的任何想法吗?

thank you =) 谢谢=)

Instead of using scale and drawBitmap try using this method: 代替使用scale和drawBitmap,请尝试使用以下方法:

canvas.drawBitmap(bitmap, src, dst, paint);

You probably should call it this way: 您可能应该这样称呼它:

canvas.drawBitmap(this.backgroundMap, null, new Rect(0, 0, 1196, 720), null);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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