如何将Image设置为Canvas类型对象

时间:2014-05-25 05:37:21

标签: android canvas

我想设置背景图片而不是 canvas = null 请帮我做。我已经发布了我使用的代码。

public void run() {
        Canvas canvas;
        Log.d(TAG, "Starting game loop");
        //begin infinite loop while(running=true)
        while (running) {
            canvas = null;
            // try locking the canvas for exclusive pixel editing
            // in the surface
            try {
                canvas = this.surfaceHolder.lockCanvas();
                synchronized (surfaceHolder) {
                    // update game state 
                    this.gamePanel.update();
                    // render state to the screen
                    // draws the canvas on the panel
                    this.gamePanel.render(canvas);              
                }
            } finally {
                // in case of an exception the surface is not left in 
                // an inconsistent state
                if (canvas != null) {
                    surfaceHolder.unlockCanvasAndPost(canvas);
                }
            }   // end finally
        }
    }

}

0 个答案:

没有答案