Android画布路径实时表现
我想在 15 分钟内绘制(4 或 5 个)实时图表,可视化大量数据(每 30 毫秒一个新值)。我正在使用 Path,但当我想要显示超过 20000 个值并平移画布时,它似乎工作得非常慢,并且每秒都变得更糟。我也尝试过使用drawLine,但它根本不能流畅工作。
有没有人有比 Path 更好的解决方案?或者也许我做错了什么?我当前的解决方案是:我在开始时初始化路径,然后每次获得新值时向其中添加一个新行,然后翻译画布。
I want to draw (4 or 5) real-time charts visualizing a lot of data (a new value every 30ms) within 15 minutes. I am using Path but it seems to work very slowly when I want to display over 20000 values and translate the canvas and it gets worse every second. I also tried using drawLine but it doesn't work fluently at all.
Does anyone have any ideas about a better solution than Path? Or maybe I am doing something wrong? My current solutio is : I initialize the Path in the beginning and then just add a new line to it every time I get a new value, then I translate the canvas.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
无论您使用什么方式,显示 20 000 个值的路径都可能会很慢,即使在 OpenGL 中,也只是将大量数据发送到图形芯片进行绘制...
“正确”的方法(性能方面)是可能会缓存尽可能多的东西,并只绘制需要绘制的内容。例如,您可以将前 N 个点绘制到位图,然后仅对接下来的 M 个点使用路径(并为前面的点绘制位图)。绘制位图非常快。因此,您可以偶尔刷新位图(这将花费更多时间),然后绘制剩余的点。
您还可以决定采用更短的路径:您真的需要 20 000 个值吗?您不能将点按 5 × 5 或 10 × 10(甚至更多)分组吗?目前,屏幕宽度最多为 1280 像素……
Displaying a path of 20 000 values will probably be slow whatever you use, even in OpenGL, it's just a lot of data to send to the graphics chip to draw...
The "correct" way to do it (performance-wise) is probably to cache as much stuff as possible, and draw only what needs to be drawn. You could for example draw to a bitmap the first N points, and then only use a path for the next M points (and draw the bitmaps for the previous ones). Drawing a bitmap is pretty fast. So once in a while, you could just refresh your bitmap (which will take a bit more time) and then plot the remaining points.
You could also decide to have a shorter path : do you really need 20 000 values ? Couldn't you be grouping points 5 by 5 or 10 by ten (or even more) ? Currently, the screens are at most 1280 pixels wide anyways...
是否在每个 onDraw() 中绘制所有这些内容?这就是为什么它很慢。首先,没有人能看到每 30 毫秒的变化。因此,继续将更新绘制到缓存位图中,然后调用 invalidate()。然后在 onDraw() 中只需将该位图复制到画布上。
Are drawing all of that in every onDraw()? That's why it's slow. First of all, nobody can see changes every 30ms. So keep drawing updates into a cache bitmap, then call invalidate(). Then in onDraw() just copy that bitmap onto the canvas.
无论如何,用画布绘制超过 20000 条线都会很慢。我敢打赌,在这个问题上你必须选择 openGL。此链接可能会有所帮助: http: //obviam.net/index.php/opengl-es-with-android-switching-from-canvas-to-opengl/
Drawing over 20000 lines with canvas is going to be slow, no matter what. My bet is that you have to go with openGL on this one. This link might be helpful: http://obviam.net/index.php/opengl-es-with-android-switching-from-canvas-to-opengl/