0
这是我的代码在Sprite
类:比例位图SurfaceView
public class Sprite {
int x, y, vx, vy;
private Bitmap texture;
public Sprite(Bitmap texture) {
this.texture = texture;
}
public int getWidth() {
return texture.getWidth();
}
public int getHeight() {
return texture.getHeight();
}
public void draw(Canvas c) {
c.drawBitmap(texture, x, y, null);
}
}
与background.draw(c);
我画的背景。但是背景比屏幕大...
如何将它缩放到屏幕大小?
当我不想要颜色,我必须在那里写'null'? – Stupe 2012-08-07 12:05:45
你可以使用下面的方法:public void drawBitmap(Bitmap bitmap,Rect src,RectF dst,Paint paint),如果你不需要剪裁,将它传递给src null,然后创建一个dst矩形来定义绘制位图的区域(其左上角将设置位图的左上角及其宽度,高度将设置位图的宽度和高度) – victorvartan 2012-08-07 12:09:33
以及如何获取屏幕尺寸? – Stupe 2012-08-07 12:10:50