0
設置我的背景圖像起來surfaceCreated():SurfaceView背景減慢使用此代碼的onDraw 20-30毫秒
Bitmap background = BitmapFactory.decodeResource(getResources(), R.drawable.untitled);
float heightScale = ((float)background.getHeight())/(float)this.getHeight();
float widthScale = (float)background.getWidth()/(float)this.getWidth();
float scale = heightScale > widthScale ? widthScale : heightScale;
int newWidth = Math.round((float)background.getWidth()/scale);
int newHeight = Math.round((float)background.getHeight()/scale);
scaled = Bitmap.createScaledBitmap(background, newWidth, newHeight, true);
縮放是受保護的位圖。在的onDraw()函數,我有這樣的:
canvas.drawBitmap(scaled, 0, 0, null); // draw the background
減慢20-30毫秒我的畫相比,使用這樣的:
canvas.drawColor(Color.Black);
有沒有解決這個辦法嗎?加快背景onDraw函數?我注意到,如果我不設置背景,應用程序不會清除我繪製的精靈。