电泳EPLAY出图

电泳EPLAY串口传输的图形数据表示是4位表示一个Y座标。把空格去掉,按Y座标画折线图就行。(知道4位一个Y就简单了直接是十进制额)

数据示例(按4个字符处理一个Y座标)

/s testStr="   2   0   0   1   3   4   6   7   8   9  12  14  17  19  24  32  43  57  73  93 124 168 228 311 417 550 708 891109112991505169618621990207321032080200618851725153713311119 914 724 556 412 297 209 146 102  73  57  49  51  57  66  80  98 124 158 199 250 315 398 509 654 8411073134716612007236627163028327734433510347333393124284825342202186715451249 992 775 599 456 347 264 205 165 137 116 103  97  98 107 120 137 157 182 215 259 319 400 510 652 830104212801534179620572300251026672753276126892546234721051841156712971040 805 600 432 303 210 148 108  84  69  62  60  63  66  69  68  64  60  60  68  86 115 158 214 287 378 488 617 764 9261092125013871488154415491503140812741112 937 766 609 473 362 276 213 168 137 120 113 113 116 125 138 157 177 202 232 269 314 371 444 539 661 817101312501532185322102589297133323645388640404094404538903640331129242504207716691299 982 722 516 361 250 176 129 101  84  71  62  52  45  38  35  32  31  30  30  30  31  32  35  37  38  37  35  31  28  24  21  20  21  23   5   0  53  97 140 179 233"
	//s datastr=testStr
	//s data=""
	s ystr=""
	f i=1:4:($l(datastr)-20) d
	.s curNum=$REPLACE($e(datastr,i,i+3)," ","")
	.//s data=data_$lb(+curNum)
	.i $l(ystr) s ystr=ystr_"^"_(curNum)
	.e  s ystr=ystr_(curNum)

然后按标准画折线图就OK了

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LIS.BLL.ImageCore;
using System.Drawing;
using System.Data;
using System.IO;
using System.Drawing.Drawing2D;
namespace LIS.Mach.ImageDeal
{
    ///<summary  NoteObject="Class">
    /// [功能描述:EPALY电泳画折线图] <para/>
    /// [创建者:zlz] <para/>
    /// [创建时间:2018年08月15日] <para/>
    ///<说明>
    ///  [说明:[功能描述:EPALY电泳画折线图]<para/>
    ///</说明>
    ///<修改记录>
    ///    [修改时间:本次修改时间]<para/>
    ///    [修改内容:本次修改内容]<para/>
    ///</修改记录>
    ///<修改记录>
    ///    [修改时间:本次修改时间]<para/>
    ///    [修改内容:本次修改内容]<para/>
    ///    M端触发代码,其他的和监听程序一样
    ///    s retObj=##Class(wbsLisMsgAsyncHandler.LISMsg.wbsLisDrawImageAsyncHandlerSoap).%New()
    ///    s ret=retObj.DrawImage(epis,ystr,mi,"MI.MIFEPALY","-1","","LIS.Mach.ImageDeal.ImageDealEPALY,LIS.Mach.ImageDeal")
    ///</修改记录>
    ///</summary>
    public class ImageDealEPALY : BaseDeal, IDrawImage
    {
        /// <summary>
        /// 绘图方法
        /// </summary>
        /// <param name="epis">流水号</param>
        /// <param name="result">结果</param>
        /// <param name="machID">仪器ID</param>
        /// <param name="dealProcess">处理M</param>
        /// <param name="index">-1认为传到最后</param>
        /// <param name="otherPara">其他参数</param>
        /// <param name="dealClass">C#处理类格式:类全名,不带后缀的动态库名</param>
        /// <returns>是否成功</returns>
        public bool DrawImage(string epis, string result, string machID, string dealProcess, string index, string otherPara, string dealClass)
        {
            string imgTmpPath = "";
            try
            {
                //分割得到数据
                string[] dataArr = result.Split('^');
                List<double> ddata = new List<double>();
                double maxY = 0;
                foreach (var d in dataArr)
                {
                    if (d == "")
                    {
                        continue;
                    }
                    double curd = Convert.ToDouble(d);
                    if (maxY < curd)
                    {
                        maxY = curd;
                    }
                    ddata.Add(curd);
                }
                bool isDrawColor = false;
                if (otherPara == "1")
                {
                    isDrawColor = true;
                }
                double width = ddata.Count;
                double height = 300;
                //x的最小偏移量
                double xmin = width / ddata.Count;
                //y的最小偏移量
                double ymin = (height - 10) / maxY;
                Bitmap img = new Bitmap(Convert.ToInt32(width), Convert.ToInt32(height));
                //画纵座标
                Graphics g = Graphics.FromImage(img);
                g.SmoothingMode = SmoothingMode.AntiAlias;
                g.Clear(Color.White);
                Pen pen = new Pen(Color.Black);
                Pen penYellow = new Pen(Color.Yellow);
                penYellow.Width = 2;
                Pen penred = new Pen(Color.Red);
                pen.Width = 1;
                g.DrawLine(pen, 2, Convert.ToInt32(height - 2), Convert.ToInt32(width), Convert.ToInt32(height - 2));
                g.DrawLine(pen, 2, Convert.ToInt32(height - 2), 1, 5);
                for (int i = 1; i < ddata.Count; i++)
                {
                    if (isDrawColor)
                    {
                        g.DrawLine(penred, Convert.ToInt32((i) * xmin), Convert.ToInt32(height), Convert.ToInt32((i) * xmin), Convert.ToInt32(height - ddata[i] * ymin));
                    }
                    if (i < ddata.Count - 1)
                    {
                        //捕获波谷
                        if (ddata[i - 1] > ddata[i] && ddata[i + 1] > ddata[i])
                        {
                            g.DrawLine(penYellow, Convert.ToInt32((i) * xmin), Convert.ToInt32(height - 13), Convert.ToInt32((i) * xmin), Convert.ToInt32(height));
                        }
                    }
                    g.DrawLine(pen, Convert.ToInt32((i - 1) * xmin), Convert.ToInt32(height - ddata[i - 1] * ymin), Convert.ToInt32((i) * xmin), Convert.ToInt32(height - ddata[i] * ymin));
                }
                //判断C盘trak是否存在
                string tmpPath = @"C:\TRAK\TmpMach";
                if (!Directory.Exists("C:\\TRAK"))
                {
                    //新建文件夹
                    Directory.CreateDirectory("C:\\TRAK");
                }
                if (!Directory.Exists(tmpPath))
                {
                    //新建文件夹   
                    Directory.CreateDirectory(tmpPath);
                }
                if (File.Exists(tmpPath + "\\" + epis + ".bmp"))
                {
                    File.Delete(tmpPath + "\\" + epis + ".bmp");
                }
                imgTmpPath = tmpPath + "\\" + machID + "-" + epis + ".bmp";

                img.Save(imgTmpPath);
                img.Dispose();
                string ftpPath = "";
                FtpService ftp = GetFtpHelper(machID, dealProcess, out ftpPath);
                ////上传图片
                ftp.Upload(imgTmpPath);
                //保存图片
                SaveImg(machID, epis, "SerumP", ftpPath.Split('^')[3] + machID + "-" + epis + ".bmp", dealProcess);
                File.Delete(imgTmpPath);
                return true;
            }
            catch (Exception ex)
            {
                LIS.Core.Util.LogUtils.WriteExceptionLog("绘制EPALY电泳图发生错误", ex);
                if (imgTmpPath!=""&&File.Exists(imgTmpPath))
                {
                    File.Delete(imgTmpPath);
                }
            }
            return false;
        }
    }
}

效果
在这里插入图片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章