2 for 2012 for_2012 于 2013.07.17 15:16 提问

lockCanvas()返回不同canvas

每毫秒在一个canvas上画一些东西,是在canvas上添加一些细节,不是每次都重新画一遍。结果我的代码每次都返回了不同的画,这是怎么回事?

public void run() {
    this.run = true;
    Canvas canvas = null;
    while (run) {
        try {
            canvas = this.surfaceHolder.lockCanvas();
            synchronized (this.surfaceHolder) {
                Thread.sleep(delay);
                draw(new Img(canvas, size));
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
            if (canvas != null) {
            this.surfaceHolder.unlockCanvasAndPost(canvas);
            }
        }
        synchronized (this) {
            if (wait) {
                try {
                    wait();
                } catch (Exception e) {}
            }
        }
    }
}
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!