3

我实际上在做一个游戏,需要一些备份,因为 Canvas。

我用画布绘制背景。所以我为我们工作的屏幕分辨率制作了图片。在设备上,图片太小,不适合屏幕。我错过了什么让平局变小的东西吗?

这是一些代码

public class Map extends View{
int[][] mapArray = new int[32][18];
private Bitmap picture;
private Paint paint;

public Map(Context context){
    //basic init map
    super(context);

    this.setPicture(BitmapFactory.decodeResource(context.getResources(), R.drawable.newmap2));
}


public Bitmap getPicture() {
    return picture;
}

public void setPicture(Bitmap background) {
    this.picture = background;
}

@Override
protected void onDraw(Canvas canvas) {
    canvas.drawBitmap(picture, 0, 0, paint);
}

希望你能帮助我最好的问候本

4

3 回答 3

1

Maybe you put the bitmap in a high dpi directory (e.g. res/drawable-xhdpi) and your device is of a lower dpi ? In this case the image is scaled down on open. What you are doing is not safe, other devices will have other screen sizes.

于 2012-11-06T20:19:23.613 回答
0

您的设备可能具有明显不同的 DPI(像素密度),可能要高得多,这会使图像看起来比应有的小得多。如果您有一张图片可以准确显示它们的不同之处,那么调试问题可能会更容易。

于 2012-11-06T20:19:23.507 回答
0

This segments of code explain how to use the dimensions of the display to determine the amount of down sampling that should occur when loading the image. Hope that could help you

Display currentDisplay = getWindowManager().getDefaultDisplay();
int dw = currentDisplay.getWidth();
int dh = currentDisplay.getHeight();
于 2012-11-06T20:25:00.697 回答