简单的心电图

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


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

新建一个

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
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值