Android:质量差的背景

时间:2013-02-05 08:36:27

标签: android background bitmap bitmapfactory

我想问一下,即使我设置了选项,为什么背景质量很低? 我的代码:

class GameView extends SurfaceView implements SurfaceHolder.Callback {

 GameThread thread;

BitmapFactory.Options options = new BitmapFactory.Options();
int screenW;
int screenH;
int bgrW;
int bgrH;
Bitmap bgr;

public GameView(Context context, AttributeSet attrs) {
super(context);

    options.inPreferredConfig = Bitmap.Config.ARGB_8888;
    options.inSampleSize = 1;
    options.inScaled = false;
    options.inDither = false;
    bgr = BitmapFactory.decodeResource(getResources(), R.drawable.gamebg, options);
    getHolder().addCallback(this);
    setFocusable(true);
    }

@Override
public void onSizeChanged (int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);
    screenW = w;
    screenH = h;
    bgr = Bitmap.createScaledBitmap(bgr, w, h, true);
    bgrW = bgr.getWidth();
    bgrH = bgr.getHeight();
}

@Override
public void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    canvas.drawBitmap(bgr, 0, 0, null);
}

由于在此论坛上发现的一些答案,上面的代码应该是正确的。我想知道onDraw()或onSizeChanged()区域是否可能遗漏了一些声明。

1 个答案:

答案 0 :(得分:0)

尝试使用Nine-patch图像而不是简单图像: 转到

android-sdk\android-sdk-windows\tools\draw9patch

并选择所需的图像并将其转换为九个补丁 现在他们看起来很好