0

I'm a newbe when it comes to Android coding. As a first project I decided to port ZX Spectrum game. I have prepared bitmap frames of the car and buttons that are about to be scaled depending on screen size. I've put the images both in "drawable" and "drawable-hdpi" folders and it seems to work on my LG Leon phone, but not working on other phones. It looks like the image isn't scaled. https://mechanism.fr/misc/not_scaled.png

here's my code: declaration of the variables:

    Rect source1;
    Rect dest1;
    Rect arrow_box;
    Rect left_box;
    Rect right_box;
    Rect up_box1;
    Rect down_box1;
    Rect up_box2;
    Rect down_box2;

example of calculating one pair of the Rect dimensions:

    private void calculateDimensions(){
(...)
            source1=new Rect(0,0,128,100);
            arrow_box=new Rect(0,0,300,300);
 left_box=new Rect((int)(0+boxxy/2),(int)(wysokosc*0.7),(int)(0+boxxy/2+boxxy),(int)(wysokosc*0.7+boxxy));

and the code responsible for drawing:

            Paint drawPaint2 = new Paint();
                canvas.drawBitmap(arrow_left_off,arrow_box,left_box,drawPaint2);
                canvas.drawBitmap(arrow_right_off,arrow_box,right_box,drawPaint2);
                canvas.drawBitmap(arrow_up_off,arrow_box,up_box1,drawPaint2);
                canvas.drawBitmap(arrow_down_off,arrow_box,down_box1,drawPaint2);
            canvas.drawBitmap(arrow_up_off,arrow_box,up_box2,drawPaint2);
            canvas.drawBitmap(arrow_down_off,arrow_box,down_box2,drawPaint2);

the dimensions are calculated after creating the canvas view:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        kanwas=new CanvasV(this);
        this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(kanwas);
        getDimensions();
        calculateDimensions();
        updateScreen();


    }

I don't quite understand what seems to be the problem.

I tried to copy the images both to "drawable" and "drawable-hdpi" folders

1 Answers1

0

Also, scale the bitmaps. Scaling the canvas doesn't do anything.

Example of scaling bitmap

bitmap=Bitmap.createScaledBitmap(src, dstWidth, dstHeight, filter)