Android中如何绘制动态曲线?
我的Android应用程序中有一个字节缓冲区,将其视为一个向量。缓冲区中的数据是动态更改的(有一个单独的线程来更新缓冲区)。我想动态绘制这些数据。
每个数据代表View中一个点的Y坐标,将连续的点连接起来形成一条曲线。由于缓冲区定期更新,曲线看起来像平滑地向前移动。
首先,我通过在View的onDraw(Canvas canvas)方法中画线来实现,但是效果很差。当调用invalidate方法过于频繁时,CPU消耗非常大。
于是我改用SurfaceView,在单独的线程中绘制动态曲线,但是还是不太理想。
我想知道是否有什么好的方法可以实现这一点。OpenGL ES是否是一个选择?
I have a byte buffer in my Android application,consider it as a vector.The data in the buffer is changed dynamically(There is a separate thread to update the buffer).I want to draw these data dynamically.
Every data represents a point's Y coordinate in the View,connect the consecutive points to form a curve.As the buffer is updated periodically,the curve looks like moving forward smoothly.
Firstly,I implement this by drawing lines in the View's onDraw(Canvas canvas) method,but it is very ineffective.When calling invalidate method is too frequently, the CPU consume is very heavy.
So I change to use the SurfaceView, draw the dynamic curve in the separate thread, but It is still not satisfactory.
I want to know whether there is any good methods to achieve this.Whether is OpenGL ES a choice?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 OpenGL ES 1.0 中,您可以在
GL_LINES
模式下使用glDrawArrays
。它将完全执行Canvas
对数据所做的操作,但速度要快得多In OpenGL ES 1.0 you can use
glDrawArrays
inGL_LINES
mode. It will do exactly what theCanvas
is doing with your data, but considerably faster