bemeyer
bemeyer

Reputation: 6221

Canvas draws Bitmap smaller than orginal Picture

I actually work on an Game and need some backup because Canvas.

I draw a background with canvas. So i made Picture exactly for the resolution of the screen we work on. On the device the picture is to small and dont fitt to the screen. Did i miss something that the draw makes it smaller?

Here is some code

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);
}

Hope you can help me out Best regards Ben

Upvotes: 3

Views: 1316

Answers (3)

Numair
Numair

Reputation: 1062

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();

Upvotes: 0

yoah
yoah

Reputation: 7230

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.

Upvotes: 1

Dacheng
Dacheng

Reputation: 156

Your device may have a significantly different DPI (pixel density), probably much higher, which would make it look like the image is much smaller than it should be. If you have a picture to show exactly how different they are, it may be easier to debug the issue.

Upvotes: 0

Related Questions