如何将位图大小调整到设备屏幕?

时间:2015-03-14 01:47:50

标签: android bitmap

当我向类扩展SurfaceView时添加背景大尺寸位图时,它不适合屏幕,其中一半消失:

公共课BackGround {

Bitmap backBitmap;
int screenWidth;
int x;
int y;
AapView appview;

public BackGround(Bitmap bitmap, int screen_w, Aapview aapV){

    this.backBitmap = bitmap;
    this.screenWidth = screen_w;
    this.x = 0;
    this.y = 0;
    aapview = aapV;

}

public void draw(Canvas canvas){

    if(canvas != null){
        canvas.drawBitmap(backBitmap, x, y, null);


    }
}

}


public AapView(Context context,Mainapp app,int screen_width,int screen_height){         超级(上下文);

    background = new BackGround(BitmapFactory.decodeResource(getResources(),    R.drawable.back_img), screen_width, this);

    }

如何使背景位图适合屏幕?

1 个答案:

答案 0 :(得分:0)

您可以使用以下代码调整位图大小。

int h = 320; // Height in pixels 
int w = 480; // Width in pixels 
Bitmap scaled = Bitmap.createScaledBitmap(largeBitmap, h, w, true);