Android 心电图

发布于 2024-11-08 03:27:41 字数 111 浏览 0 评论 0原文

我想制作一个实时显示有氧图的应用程序。这意味着我想测量心率并希望在我的应用程序中以图表形式显示比特率。但我想画有氧图。我已经浏览了许多示例图形代码,但没有得到任何绘制有氧图的线索。有没有任何机构提供任何线索?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

樱娆 2024-11-15 03:27:41

对于这个特定的应用程序,您可能需要使用 Path 和 SurfaceView “手动”绘制图形。

在初始化期间准备好 Paint 实例:

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

当您需要更新图形时,清除场景并构建线条路径(根据您的需要进行调整):

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。

如果你希望你的图表具有实时动画效果(即向左滑动,而数据从右侧传入),你可以以类似于著名的 LunarLander 示例的方式在 SurfaceView 上绘制(以下代码是简化版本):

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() 以及所有绘图代码。

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);

You may also use quadTo or cubicTo instead of lineTo.

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); 
            }
        }
    }
}

Where mSurfaceHolder is obtained by calling yourSurfaceView.getHolder() and doDraw is where
you call canvas.drawPath() and all your drawing code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文