【问题标题】:how can I fit the bitmap size to a device screen?如何使位图大小适合设备屏幕?
【发布时间】:2015-03-14 01:47:49
【问题描述】:

当我为扩展SurfaceView的类添加背景大尺寸位图时,它不适合屏幕并且一半消失了:

公共类背景{

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

    }

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

【问题讨论】:

  • 你是如何确定屏幕宽度的?度量单位是 dp 还是 px?就个人而言,我也会将位图放在 assets 文件夹中,以确保没有看不见的自动缩放问题。

标签: android bitmap


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-27
    • 1970-01-01
    相关资源
    最近更新 更多