我从网络接收样本(浮点数组)并将它们绘制为 SurfaceView 中的曲线。样本会定期更新,因此曲线是动态的。在我的程序中,我创建了一个将绘制曲线的位图,如下所示:
Bitmap bmp = Bitmap.createBitmap(width, height, Config.ARGB_4444);
Canvas canvas = new Canvas(bmp);
drawCurve(canvas);
void drawCurve(Canvas canvas, float[] buffer) {
...
canvas.drawLine(x1, buffer[i], x2, buffer[i+1], paint);
...
}
...
private class RenderThread extends Thread {
public void run() {
c = mHolder.lockCanvas(null);
c.drawBitmap(bmp, 0, 0, null);
mHolder.unlockCanvasAndPost(c);
...
}
}
我想支持曲线可以放大和缩小。为了有效地绘制曲线,drawCurve方法只是更新新样本,即擦除旧区域,并在该区域绘制新样本。我能怎么做?谢谢!