我想问为什么即使我设置了选项,背景质量仍然很低?我的代码:
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() 区域是否缺少某些声明。