简单的心电图

来源:互联网 发布:破解音乐付费软件 编辑:程序博客网 时间:2024/04/27 08:13

    好几天没写博客了,想到这几天做的项目有涉及到心电图这块,拿出来分享下,顺便也说下自己遇到的问题,如果有哪位大神指导下,小弟不胜感激!


首先利用自定义控件绘制一个心电图的背景:

新建一个

CardiographView类继承View类来写:
public class CardiographView  extends View {    //画笔    protected Paint mPaint;    //折现的颜色    protected int mLineColor = Color.parseColor("#76f112");    //网格颜色    protected int mGridColor = Color.parseColor("#1b4200");    //小网格颜色    protected int mSGridColor = Color.parseColor("#092100");    //背景颜色    protected int mBackgroundColor = Color.BLACK;    //自身的大小    protected int mWidth,mHeight;    //网格宽度    protected int mGridWidth = 50;    //小网格的宽度    protected int mSGridWidth = 10;    //心电图折现    protected Path mPath ;    public CardiographView(Context context) {        this(context,null);    }    public CardiographView(Context context, AttributeSet attrs) {        this(context, attrs,0);    }    public CardiographView(Context context, AttributeSet attrs, int defStyleAttr) {        super(context, attrs, defStyleAttr);        mPaint = new Paint();        mPath = new Path();    }    @Override    protected void onSizeChanged(int w, int h, int oldw, int oldh) {        mWidth = w;        mHeight = h;        super.onSizeChanged(w, h, oldw, oldh);    }    @Override    protected void onDraw(Canvas canvas) {        canvas.drawColor(mBackgroundColor);        //画小网格        //竖线个数        int vSNum = mWidth /mSGridWidth;        //横线个数        int hSNum = mHeight/mSGridWidth;        mPaint.setColor(mSGridColor);        mPaint.setStrokeWidth(2);        //画竖线        for(int i = 0;i<vSNum+1;i++){            canvas.drawLine(i*mSGridWidth,0,i*mSGridWidth,mHeight,mPaint);        }        //画横线        for(int i = 0;i<hSNum+1;i++){            canvas.drawLine(0,i*mSGridWidth,mWidth,i*mSGridWidth,mPaint);        }        //竖线个数        int vNum = mWidth / mGridWidth;        //横线个数        int hNum = mHeight / mGridWidth;        mPaint.setColor(mGridColor);        mPaint.setStrokeWidth(2);        //画竖线        for(int i = 0;i<vNum+1;i++){            canvas.drawLine(i*mGridWidth,0,i*mGridWidth,mHeight,mPaint);        }        //画横线        for(int i = 0;i<hNum+1;i++){            canvas.drawLine(0,i*mGridWidth,mWidth,i*mGridWidth,mPaint);        }    }}

有了背景我们就可以画心电图了
为了节约这里再新建一个PathView类这里继承CardiographView类就行了:
public class PathView extends CardiographView {    List list = new ArrayList<>();    public PathView(Context context) {        super(context);    }    public PathView(Context context, AttributeSet attrs) {        super(context, attrs);    }    public PathView(Context context, AttributeSet attrs, int defStyleAttr) {        super(context, attrs, defStyleAttr);    }    @Override    protected void onDraw(Canvas canvas) {        // 重置path        mPath.reset();        //path模拟一个心电图样式        mPath.moveTo(0,mHeight/2);        int tmp = 0;        for (int i = 0; i < 81; i++) {            mPath.lineTo(tmp+20, mHeight / 2+100);            mPath.lineTo(tmp+40, mHeight / 2-100);            tmp = tmp+40;        }        //设置画笔style        mPaint.setStyle(Paint.Style.STROKE);        mPaint.setColor(mLineColor);        canvas.drawPath(mPath,mPaint);    }    public boolean isStoping = true;    private void scroll(){        if (isStoping){            scrollBy(1,0);        }else {            scrollBy(0,0);        }    }}

然后将布局搭建好就可以了!
scrollBy(1,0)就是让心电图开始移动
项目地址:点击下载
问题:我在其他项目中获取设备传过来的数据,并将数据适配到心电图上,让它获取到数据就画一个线,并且加上移动就是真正的心电图,
但是在庞大的数据面前,心电图一边获取数据一边绘制图形时会越来越卡好像涉及到内存问题。我现在还没有解决,获取的数据量很大,
几百几千万个点这个样子,如有大神有好的方案提供,小弟不胜感激!!!

0 0
原创粉丝点击