canvas.drawBitmap()不缩放图像

时间:2019-10-13 09:12:19

标签: java android canvas drawbitmap

关于Android编码,我是个新手。作为第一个项目,我决定移植ZX Spectrum游戏。我已经准备好汽车的位图框架和根据屏幕尺寸将要缩放的按钮。我将图像都放在“ drawable”和“ drawable-hdpi”文件夹中,它似乎可以在我的LG Leon手机上使用,但不能在其他手机上使用。看起来图像没有缩放。 https://mechanism.fr/misc/not_scaled.png

这是我的代码: 变量的声明:

    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;

计算一对Rect尺寸的示例:

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

以及负责绘制的代码:

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

尺寸是在创建画布视图之后计算的:

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


    }

我不太了解问题所在。

我试图将图像都复制到“ drawable”和“ drawable-hdpi”文件夹中

1 个答案:

答案 0 :(得分:0)

此外,缩放位图。缩放画布没有任何作用。

缩放位图的示例

bitmap = Bitmap.createScaledBitmap(src,dstWidth,dstHeight,过滤器)