问题描述
我想打一个应用程序实时显示心脏图。这意味着我要测量心脏位和要显示的比特率曲线在我的应用程序。但我想知道画出心图。我已经经历了很多示例图表codeS走了,但力得到任何线索,绘制心图。是否有任何身体的任何线索?
I want to make an app which shows cardio graph in real time. That means i want to measure heart bit and want to show the bit rate in graph in my application. But i wondering to draw the cardio graph. I have gone through many sample graph codes but dint get any clue to draw cardio graph. Is there any clue from any body?
感谢和放大器;问候
推荐答案
对于这个特定的应用程序,您可能希望使用路径和SurfaceView绘制图形手动。
For this specific application, you may want to draw the graph "by hand" using Path and a SurfaceView.
在初始化过程中得到一个油漆实例,准备:
Get a Paint instance ready during initialization:
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(3);
paint.setColor(Color.GREEN); //Change to what you want
当您需要更新的图形,清场,并建行路径(此相适应您的需求):
When you need to update the graphic, clear the scene and build the line path (adapt this to your needs) :
canvas.drawColor(Color.WHITE);
Path path = new Path();
path.moveTo(0, yourValueAt(0));
for(int sec = 1; sec < 30; sec++)
path.lineTo(sec, yourValueAt(sec));
canvas.drawPath(path, paint);
您也可以使用quadTo或cubicTo代替了lineTo。
You may also use quadTo or cubicTo instead of lineTo.
如果你希望你的图有一个实时动画效果(即向左滑动,而数据即将在右侧),您可以利用类似的方式,以著名的LunarLander例如SurfaceView(以下code是一个简化版本):
If you want your graph to have a realtime animation effect (i.e. sliding to the left while data is coming on the right), you may draw on a SurfaceView in a similar way to the famous LunarLander example (following code is a simplified version):
class DrawingThread extends Thread {
@Override
public void run() {
while (running) {
Canvas c = null;
try {
c = mSurfaceHolder.lockCanvas(null);
synchronized (mSurfaceHolder) {
doDraw(c);
}
} finally {
if (c != null) mSurfaceHolder.unlockCanvasAndPost(c);
}
synchronized (this) {
//Optional but saves battery life.
//You may compute the value to match a given max framerate..
this.wait(SOME_DELAY_IN_MS);
}
}
}
}
在哪里mSurfaceHolder是通过调用获得 yourSurfaceView.getHolder()
和 doDraw
是你叫 canvas.drawPath()
和所有的绘图code。
Where mSurfaceHolder is obtained by calling yourSurfaceView.getHolder()
and doDraw
is whereyou call canvas.drawPath()
and all your drawing code.
这篇关于心图形为Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!