我有一个在后台线程上绘制的自定义视图,与定义为here的BallThread相似。
在我的特定应用程序中,我绘制了一行像素,每个像素都有一个独特的颜色。当下一组数据进入时,当前绘制的像素向上移动,添加一个新行,并重新绘制所有内容。该面板还支持平移和缩放。
我的问题是,随着时间的推移,我有更多像素要跟踪并重新绘制,平移和缩放的动画会变得更加困难。我觉得我需要绘制的东西似乎超出了Canvas能够及时支持的限制。
class DrawingThread extends Thread {
private SurfaceHolder _surfaceHolder;
private DrawingView _panel;
private boolean _run = false;
public DrawingThread(SurfaceHolder surfaceHolder, DrawingView panel) {
_surfaceHolder = surfaceHolder;
_panel = panel;
}
public void setRunning(boolean run) {
_run = run;
}
public SurfaceHolder getSurfaceHolder() {
return _surfaceHolder;
}
@Override
public void run() {
Canvas canvas;
while (_run) {
canvas = null;
try {
canvas = _surfaceHolder.lockCanvas(null);
synchronized (_surfaceHolder) {
_panel.doDraw(canvas);
}
Thread.sleep(20);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
// do this in a finally so that if an exception is thrown
// during the above, we don't leave the Surface in an
// inconsistent state
if (canvas != null) {
_surfaceHolder.unlockCanvasAndPost(canvas);
}
}
}
}
}
我可以做的其他事情可以比Canvas更快地处理像素绘制(例如canvas.drawPixel())吗?