关于性能,没有分析我们不能说。
可能是您的目标手机上的线条绘制是硬件加速的,您应该在每一帧都使用线条绘制图元从头开始绘制图形。
另一方面,图像缓冲区的直接像素操作是:
创建一个大小合适的图像并将其清除为“background_color”。此图像需要具有 setpixel() 功能。
有一个值数组记录每次 x 的 y,因此对于任何列,您都知道上次绘制图表的位置。
将此“chart_image”和“chart_array”视为循环缓冲区。对于每个时间步:
Y = ...;
X = time_since_start % chart_width;
chart_image.setpixel(X,chart_array[X],background_color); // clear previous line
chart_array[X] = Y;
chart_image.setpixel(X,chart_array[X],foreground_color); // draw new plot
现在你需要对它进行 blit。您需要对图像进行两次 blit:
X = time_since_start % chart_width;
// the newest data is on the left of the chart_image but gets drawn on the right side of the output
blit(out_x+X,out_y, // destination coordinates
chart_image,
0,0, // top left of part of chart_image to blit
X,chart_height); // bottom right of chart_image part
// the oldest data is on the right of the chart_image but gets drawn on the left side of the output
blit(out_x,out_y,
chart_image,
X,0,
chart_width,chart_height);
如果您想使用线条而不是单个像素,事情会变得更加棘手,但是 drawline() 而不是 setpixel() 也可以使用这种方法。
(很抱歉不知道 Android API;但方法是通用的。)