Android: How do I scale a bitmap to fit the screen size using canvas/draw bitmap?

前端 未结 3 1308
没有蜡笔的小新
没有蜡笔的小新 2021-01-21 13:15

I am taking an image and drawing it to the screen using canvas. I want to scale it based on the screen size.

This is what I tried, but it cuts off a large chunk of the

3条回答
  •  难免孤独
    2021-01-21 13:57

    Rect frameToDraw = new Rect(0, 0, width, height);
    RectF whereToDraw = new RectF(0, 0, width, height);
    

    Take a look at the above code. Your are not scaling the picture. You are simply taking a part of the picture (in this case the whole picture) and pasting it somewhere (in this case the size of the original picture).

    The width and heigth of the frameToDraw rectangle should be the width and height of your picture.

提交回复
热议问题