ECGPrint/1200Gxml心电图绘制/EcgDataDraw_New.cs
2024-12-25 17:24:22 +08:00

902 lines
44 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.IO;
namespace _1200Gxml心电图绘制
{
public class EcgDataDraw_New
{
int Amplitude = 10;//振幅
int PaperSpeed = 25;
double AmplificationFactor = 140.00;
//int AmplificationFactor = 60;
int SamplingRate = 300;
int LeadCount = 12;
int byteLength = 2;
int Dpi = 96;
double LenthPerInch = 25.4;
int BaseLine = 0;
int LeadHeight = 0;
Pen Ecg_Pen;
Graphics Ecg_Graphics;
Bitmap Ecg_Canvas;
public List<int> LeadInfo = new List<int>();
Dictionary<int, List<double>> EcgDataList;
int FreePixs = 0;
Point FirstPosition = new Point(0, 0);
Point SecondPosition = new Point(0, 0);
Dictionary<string, Point> FirstPointArray = new Dictionary<string, Point>();
//存放心电数据的字典 按照 每导联顺序进行存储
Dictionary<int, List<float>> EcgData_Dic = new Dictionary<int, List<float>>();
/// <summary>
///
/// </summary>
/// <param name="pb"></param>
/// <param name="Leads"></param>
/// <param name="EcgTable"></param>
/// <param name="NewDpi"></param>
public void InitEcgParameter(Bitmap btmp, int leadCount, Dictionary<int, List<float>> EcgTable, int NewDpi, List<int> leadinfo)
{
//string[] WavePara = File.ReadAllText(Application.StartupPath + @"\WavePara.txt").Trim().Split(',');
//SamplingRate = int.Parse(WavePara[0].Trim());
//AmplificationFactor = double.Parse(WavePara[1].Trim());
SamplingRate =300;
AmplificationFactor = 10;
Ecg_Canvas = btmp;
Ecg_Graphics = Graphics.FromImage(Ecg_Canvas);
Ecg_Graphics.Clear(Color.White);//填充指定颜色
LeadCount = leadCount;
LeadInfo = leadinfo;
BaseLine = (btmp.Height / LeadInfo.Count) / 2;
LeadHeight = (btmp.Height / (LeadInfo.Count/2));
Dpi = NewDpi;
EcgData_Dic = EcgTable;
Ecg_Pen = new Pen(Color.Gray, float.Parse("0.5"));
FreePixs = int.Parse(Math.Round((double.Parse(Dpi.ToString()) / LenthPerInch) * 5).ToString());
}
/// <summary>
/// 把识别的R波位置标示出来
/// </summary>
/// <param name="rPosList"></param>
public void drawRWavePos(List<int> rPosList)
{
Ecg_Pen = new Pen(Color.Green, float.Parse("1"));
double IntervalPixCountPerPoint = double.Parse("0.102");
for (int i = 0; i < rPosList.Count; i++)
{
double x = double.Parse(rPosList[i].ToString()) * IntervalPixCountPerPoint * 3.3;
int nextX = (int.Parse(Math.Round(x).ToString()));
Point pt1 = new Point(nextX,0); Point pt2 = new Point(nextX, 1024);
Ecg_Graphics.DrawLine(Ecg_Pen, pt1, pt2);
}
}
/// <summary>
/// 绘制心电波形
/// </summary>
public void Draw_EcgWave()
{
Ecg_Pen = new Pen(Color.Black, float.Parse("1"));
//double IntervalPixCountPerPoint = (double.Parse(PaperSpeed.ToString()) / double.Parse(SamplingRate.ToString())) * (double.Parse(Dpi.ToString()) / LenthPerInch);
//double IntervalPixCountPerPoint = double.Parse("0.095");
//double IntervalPixCountPerPoint = double.Parse("0.134");
double IntervalPixCountPerPoint = double.Parse("0.102");
//double IntervalPixCountPerPoint = double.Parse("0.126");
for (int i = 0; i < LeadInfo.Count; i++)
{
int LeadIndex = LeadInfo[i];//取导联下标 0 1 2 3 ...11
if (i < 6)
{
BaseLine = (Ecg_Canvas.Height / (LeadInfo.Count / 2)) / 2 + (i * LeadHeight);
FirstPosition.Y = BaseLine;
FirstPosition.X = FreePixs;
SecondPosition.Y = BaseLine;
SecondPosition.X = FreePixs;
Point FP = new Point(FirstPosition.X + FreePixs, FirstPosition.Y);
FirstPointArray.Add(LeadIndex.ToString(), FP);
}
else
{
BaseLine = (Ecg_Canvas.Height / (LeadInfo.Count / 2)) / 2 + ((i - 6) * LeadHeight);
FirstPosition.Y = BaseLine;
FirstPosition.X = FreePixs + Ecg_Canvas.Width / 2;
SecondPosition.Y = BaseLine;
SecondPosition.X = FreePixs + Ecg_Canvas.Width / 2;
Point FP = new Point(FirstPosition.X + FreePixs, FirstPosition.Y);
FirstPointArray.Add(LeadIndex.ToString(), FP);
}
if (EcgData_Dic.Count > 0)
for (int b = 0; b < EcgData_Dic[LeadIndex].Count; b++)
{
if (i < 6)
{
if (FirstPosition.X > Ecg_Canvas.Width / 2 - 5)
break;
}
else
{
if (FirstPosition.X > Ecg_Canvas.Width)
break;
}
//double c = double.Parse(EcgData_Dic[LeadIndex][b].ToString());
//double d = double.Parse((double.Parse(Dpi.ToString()) / double.Parse("96")).ToString());
//SecondPosition.Y = BaseLine - (int)(c * d);
float y_values = 0;
try
{
//y_values = EcgData_Dic[LeadIndex][b] * (float)(96 / 25.4)*10;
y_values = EcgData_Dic[LeadIndex][b] * (float)(96 / 25.4) * (float)0.041;
}
catch { }
SecondPosition.Y = BaseLine - (Int32)y_values;//后一点Y轴位置
double x = double.Parse(b.ToString()) * IntervalPixCountPerPoint*3.3;
int nextX = (int.Parse(Math.Round(x).ToString()));
if (Math.Abs(FirstPosition.X - SecondPosition.X) < 5)
{
if (i < 6)
{
SecondPosition.X = nextX + FreePixs;
Ecg_Graphics.DrawLine(Ecg_Pen, FirstPosition, SecondPosition);
FirstPosition = SecondPosition;
//Ecg_Graphics.DrawLine(new Pen(Color.Green, float.Parse("1")), FirstPosition.X, BaseLine+150, SecondPosition.X, BaseLine + 150);
}
else
{
SecondPosition.X = Ecg_Canvas.Width / 2 + FreePixs + nextX;
Ecg_Graphics.DrawLine(Ecg_Pen, FirstPosition, SecondPosition);
FirstPosition = SecondPosition;
}
}
else
FirstPosition = SecondPosition;
}
}
}
/// <summary>
/// 绘制心电波形
/// </summary>
public void Draw_EcgWave(int Draw_InitHeight,int BottomHeight)
{
FirstPointArray.Clear();
Draw_InitHeight = Draw_InitHeight * FreePixs;
BottomHeight = BottomHeight * FreePixs;
Ecg_Pen = new Pen(Color.Black, float.Parse("2"));
//double IntervalPixCountPerPoint = (double.Parse(PaperSpeed.ToString()) / double.Parse(SamplingRate.ToString())) * (double.Parse(Dpi.ToString()) / LenthPerInch);
//double IntervalPixCountPerPoint = double.Parse("0.134");
double IntervalPixCountPerPoint = double.Parse("0.296");
for (int i = 0; i < LeadInfo.Count; i++)
{
int LeadIndex = LeadInfo[i];//取导联下标 0 1 2 3 ...11
if (i < 6)
{
//BaseLine = (Ecg_Canvas.Height / (LeadInfo.Count / 2)) / 2 + (i * LeadHeight);
BaseLine = ((Ecg_Canvas.Height - Draw_InitHeight - BottomHeight) / (LeadInfo.Count / 2)) / 2 + (i * ((Ecg_Canvas.Height - Draw_InitHeight - BottomHeight) / (LeadInfo.Count / 2))) + Draw_InitHeight;
FirstPosition.Y = BaseLine;
FirstPosition.X = FreePixs;
SecondPosition.Y = BaseLine;
SecondPosition.X = FreePixs;
Point FP = new Point(FirstPosition.X + FreePixs, FirstPosition.Y);
FirstPointArray.Add(LeadIndex.ToString(), FP);
}
else
{
BaseLine = ((Ecg_Canvas.Height - Draw_InitHeight - BottomHeight) / (LeadInfo.Count / 2)) / 2 + ((i - 6) * ((Ecg_Canvas.Height - Draw_InitHeight - BottomHeight) / (LeadInfo.Count / 2))) + Draw_InitHeight;
FirstPosition.Y = BaseLine;
FirstPosition.X = FreePixs + Ecg_Canvas.Width / 2;
SecondPosition.Y = BaseLine;
SecondPosition.X = FreePixs + Ecg_Canvas.Width / 2;
Point FP = new Point(FirstPosition.X + FreePixs, FirstPosition.Y);
FirstPointArray.Add(LeadIndex.ToString(), FP);
}
for (int b = 0; b < EcgData_Dic[LeadIndex].Count; b+=3)
{
if (i < 6)
{
if (FirstPosition.X > Ecg_Canvas.Width / 2 - 5)
break;
}
else
{
if (FirstPosition.X > Ecg_Canvas.Width)
break;
}
//double c = double.Parse(EcgData_Dic[LeadIndex][b].ToString());
//double d = double.Parse((double.Parse(Dpi.ToString()) / double.Parse("96")).ToString());
//SecondPosition.Y = BaseLine - (int)(c * d);
float y_values = 0;
try
{
//y_values = EcgData_Dic[LeadIndex][b] * (float)(300 / 25.4)*10;
y_values = EcgData_Dic[LeadIndex][b] * (float)(300 / 25.4) * (float)9.5;
}
catch { }
SecondPosition.Y = BaseLine - (Int32)y_values;//后一点Y轴位置
double x = double.Parse(b.ToString()) * IntervalPixCountPerPoint;
int nextX = (int.Parse(Math.Round(x).ToString()));
if (Math.Abs(FirstPosition.X - SecondPosition.X) < 5)
{
if (i < 6)
{
SecondPosition.X = nextX + FreePixs;
Ecg_Graphics.DrawLine(Ecg_Pen, FirstPosition, SecondPosition);
FirstPosition = SecondPosition;
}
else
{
SecondPosition.X = Ecg_Canvas.Width / 2 + FreePixs + nextX;
Ecg_Graphics.DrawLine(Ecg_Pen, FirstPosition, SecondPosition);
FirstPosition = SecondPosition;
}
}
else
FirstPosition = SecondPosition;
}
}
}
/// <summary>
/// 绘制心电报告的报告头
/// </summary>
public void Draw_ReportHeadInfo(string ReportHeadTile, string SectionName,string IdStr)
{
Pen pen_1 = new Pen(Color.Black, float.Parse("4"));
Font font1 = new Font("隶书", 20);
Brush brush = Brushes.Black;
PointF point2 = new PointF(Ecg_Canvas.Width/2-300, FreePixs/2);
Ecg_Graphics.DrawString(ReportHeadTile, font1, brush, point2);
Font font = new Font("宋体", 10);
//PointF point = new PointF(10, FreePixs * 3-20);
//Ecg_Graphics.DrawString("科室:" + SectionName, font, brush, point);
PointF pointId = new PointF(Ecg_Canvas.Width - 3400, FreePixs * 4-20);
Ecg_Graphics.DrawString("ID" + IdStr, font, brush, pointId);
//PointF point1 = new PointF(Ecg_Canvas.Width-1200, FreePixs * 3-20);
//Ecg_Graphics.DrawString("报告日期:" + ReportDate, font, brush, point1);
// Ecg_Graphics.DrawLine(pen_1, 0, FreePixs * 4-60, Ecg_Canvas.Width, FreePixs * 4-60);
}
///// <summary>
///// 绘制患者的心电识别的参数
///// </summary>
//public void Draw_EcgInfo(string[] Diag_Info_List)
//{
// Pen pen_1 = new Pen(Color.Black, float.Parse("4"));
// Font font1 = new Font("宋体", 10);
// Brush brush = Brushes.Black;
// PointF point = new PointF(10, FreePixs * 4+10);
// Ecg_Graphics.DrawString(Diag_Info_List[0], font1, brush, point);//姓名
// PointF point_1 = new PointF(10, FreePixs * 5 + 25);
// Ecg_Graphics.DrawString(Diag_Info_List[1], font1, brush, point_1);//性别
// PointF point_2 = new PointF(10, FreePixs * 6 + 35);
// Ecg_Graphics.DrawString(Diag_Info_List[2], font1, brush, point_2);//年龄
// PointF point_3 = new PointF(600, FreePixs * 4 + 10);
// Ecg_Graphics.DrawString(Diag_Info_List[3], font1, brush, point_3);//P
// PointF point_4 = new PointF(600, FreePixs * 5 + 25);
// Ecg_Graphics.DrawString(Diag_Info_List[4], font1, brush, point_4);//P-R
// PointF point_5 = new PointF(600, FreePixs * 6 + 35);
// Ecg_Graphics.DrawString(Diag_Info_List[5], font1, brush, point_5);//QRS
// PointF point_6 = new PointF(1200, FreePixs * 4 + 10);
// Ecg_Graphics.DrawString(Diag_Info_List[6], font1, brush, point_6);//QT/QTC
// PointF point_7 = new PointF(1200, FreePixs * 5 + 25);
// Ecg_Graphics.DrawString(Diag_Info_List[7], font1, brush, point_7);//QRS电轴
// PointF point_8 = new PointF(1200, FreePixs * 6 + 35);
// Ecg_Graphics.DrawString(Diag_Info_List[8], font1, brush, point_8);//RV5/SV1
// PointF point_9 = new PointF(1800, FreePixs * 4 + 10);
// Ecg_Graphics.DrawString(Diag_Info_List[9], font1, brush, point_9);//心率
// Ecg_Graphics.DrawLine(pen_1, 0, FreePixs * 8, Ecg_Canvas.Width, FreePixs * 8);
//}
/// <summary>
/// 绘制患者的心电识别的参数
/// </summary>
public void Draw_EcgInfo(string[] Diag_Info_List)
{
Pen pen_1 = new Pen(Color.Black, float.Parse("4"));
Font font1 = new Font("宋体", 10);
Brush brush = Brushes.Black;
PointF point = new PointF(600, FreePixs * 4-20);
Ecg_Graphics.DrawString(Diag_Info_List[0], font1, brush, point);//姓名
PointF point_1 = new PointF(1200, FreePixs * 4 -20);
Ecg_Graphics.DrawString(Diag_Info_List[1], font1, brush, point_1);//性别
PointF point_2 = new PointF(1800, FreePixs * 4-20);
Ecg_Graphics.DrawString(Diag_Info_List[2], font1, brush, point_2);//年龄
//PointF point_4 = new PointF(600, FreePixs * 5 + 25);
//Ecg_Graphics.DrawString(Diag_Info_List[3], font1, brush, point_4);//P
PointF point_5 = new PointF(10, FreePixs * 5 + 5);
Ecg_Graphics.DrawString(Diag_Info_List[4], font1, brush, point_5);//P-R
PointF point_6 = new PointF(600, FreePixs * 5 + 5);
Ecg_Graphics.DrawString(Diag_Info_List[5], font1, brush, point_6);//QRS
PointF point_3 = new PointF(1200, FreePixs * 5 + 5);
Ecg_Graphics.DrawString(Diag_Info_List[9], font1, brush, point_3);//心率
PointF point_7 = new PointF(10, FreePixs * 6 + 35);
Ecg_Graphics.DrawString(Diag_Info_List[6], font1, brush, point_7);//QT/QTC
PointF point_8 = new PointF(600, FreePixs * 6 + 35);
Ecg_Graphics.DrawString(Diag_Info_List[7], font1, brush, point_8);//QRS电轴
PointF point_9 = new PointF(1200, FreePixs * 6 + 35);
Ecg_Graphics.DrawString(Diag_Info_List[8], font1, brush, point_9);//RV5/SV1
Ecg_Graphics.DrawLine(pen_1, 0, FreePixs * 8, Ecg_Canvas.Width, FreePixs * 8);
}
/// <summary>
/// 绘制医生的诊断结果
/// </summary>
public void Draw_DiagInfo(string DiagInfoContent,string ReportDoctorName,string ReportDate,string Filter,string collectTime,string dept)
{
string[] diagresultecontent = new string[DiagInfoContent.Length/48+1];
for (int a = 0; a < DiagInfoContent.Length / 48 + 1;a++ )
{
if (a < DiagInfoContent.Length / 48)
diagresultecontent[a] = DiagInfoContent.Substring(a * 48, 48);
else
diagresultecontent[a] = DiagInfoContent.Substring(a * 48, DiagInfoContent.Length - a * 48);
}
Pen pen_1 = new Pen(Color.Black, float.Parse("4"));
Font font1 = new Font("宋体", 12);
Brush brush = Brushes.Black;
Ecg_Graphics.DrawLine(pen_1, 0, Ecg_Canvas.Height - FreePixs * 6, Ecg_Canvas.Width, Ecg_Canvas.Height - FreePixs * 6);
PointF point1 = new PointF(10, Ecg_Canvas.Height - FreePixs * 6 + 10);
Ecg_Graphics.DrawString("诊断提示:", font1, brush, point1);//诊断结果
for (int i = 0; i < diagresultecontent.Length; i++)
{
PointF point5 = new PointF(230, Ecg_Canvas.Height - FreePixs * (6-i) + 10);
Ecg_Graphics.DrawString(diagresultecontent[i].Trim(), font1, brush, point5);//诊断结果
}
PointF pointb = new PointF(Ecg_Canvas.Width - 1800, Ecg_Canvas.Height - FreePixs * 2);
Ecg_Graphics.DrawString("科室:" + dept, font1, brush, pointb);//报告医生
PointF point2 = new PointF(Ecg_Canvas.Width - 1200, Ecg_Canvas.Height - FreePixs * 2);
Ecg_Graphics.DrawString("报告医生:" + ReportDoctorName, font1, brush, point2);//报告医生
PointF point9 = new PointF(Ecg_Canvas.Width - 600, Ecg_Canvas.Height - FreePixs * 2);
Ecg_Graphics.DrawString("报告日期:" + ReportDate, font1, brush, point9);//报告医生
PointF point10 = new PointF(1800, FreePixs * 6 + 35);
Ecg_Graphics.DrawString("25mm/s 10mm/mV " + Filter, font1, brush, point10);//振幅 走纸速度 滤波
PointF point11 = new PointF(Ecg_Canvas.Width - 600, Ecg_Canvas.Height - FreePixs * 7 - 5);
Ecg_Graphics.DrawString(collectTime, font1, brush, point11);//波形的起始时间点
Ecg_Graphics.DrawLine(pen_1, 0, Ecg_Canvas.Height - FreePixs, Ecg_Canvas.Width, Ecg_Canvas.Height - FreePixs);
}
///// <summary>
///// 绘制心电波形
///// </summary>
//public void Draw_EcgWave()
//{
// Ecg_Pen = new Pen(Color.Black, float.Parse("0.5"));
// for (int i = 0; i < LeadInfo.Count; i++)
// {
// int LeadIndex = LeadInfo[i];//取导联下标 0 1 2 3 ...11
// BaseLine = (Ecg_Canvas.Height / LeadInfo.Count) / 2 + (i * LeadHeight);
// FirstPosition.Y = BaseLine;
// FirstPosition.X = FreePixs;
// SecondPosition.Y = BaseLine;
// SecondPosition.X = FreePixs;
// Point FP = new Point(FirstPosition.X + FreePixs, FirstPosition.Y);
// FirstPointArray.Add(LeadIndex.ToString(), FP);
// for (int b = 0; b < EcgDataList[LeadIndex].Count; b++)
// {
// if (FirstPosition.X > Ecg_Canvas.Width)
// break;
// if (EcgDataList[LeadIndex][b] > 0)
// SecondPosition.Y = Math.Abs(BaseLine - EcgDataList[LeadIndex][b]);
// if (EcgDataList[LeadIndex][b] < 0)
// SecondPosition.Y = BaseLine + Math.Abs(EcgDataList[LeadIndex][b]);
// double x = double.Parse(b.ToString()) * (double.Parse(Dpi.ToString()) / double.Parse(SamplingRate.ToString()));//获得点的X轴位置
// int nextX = (int.Parse(Math.Round(x).ToString()));
// if (Math.Abs(FirstPosition.X - SecondPosition.X) < 5)
// {
// SecondPosition.X = nextX + FreePixs;
// Ecg_Graphics.DrawLine(Ecg_Pen, FirstPosition, SecondPosition);
// FirstPosition = SecondPosition;
// }
// else
// FirstPosition = SecondPosition;
// }
// }
//}
///// <summary>
///// 绘制心电图的背景网格
///// </summary>
//public void Draw_EcgBackGroundGrid()
//{
// Ecg_Pen = new Pen(Color.LightCoral, float.Parse("0.1"));
// bool shuxianFlag = false;
// double PointCountPerMM = Math.Abs(double.Parse(Dpi.ToString()) / LenthPerInch);
// int x = 0;
// int y = 0;
// for (int p = 0; p < Ecg_Canvas.Height / PointCountPerMM; p++)
// {
// for (int R = 0; R < Ecg_Canvas.Width / PointCountPerMM; R++)
// {
// if (x % 5 == 0 && !shuxianFlag)
// {
// Ecg_Graphics.DrawLine(Ecg_Pen, x, 0, x, Ecg_Canvas.Height);
// }
// x += int.Parse(Math.Round(double.Parse(PointCountPerMM.ToString("0.0"))).ToString());
// if (x < Ecg_Canvas.Width && y < Ecg_Canvas.Height)
// {
// Ecg_Canvas.SetPixel(x, y, Color.LightCoral);
// }
// else
// {
// x = 0;
// break;
// }
// }
// shuxianFlag = true;
// if (y % 5 == 0)
// {
// Ecg_Graphics.DrawLine(Ecg_Pen, 0, y, Ecg_Canvas.Width, y);
// }
// y += int.Parse(Math.Round(double.Parse(PointCountPerMM.ToString("0.0"))).ToString());
// if (y > Ecg_Canvas.Height)
// {
// break;
// }
// }
//}
/// <summary>
/// 绘制心电图的背景网格
/// </summary>
public void Draw_EcgBackGroundGrid()
{
Ecg_Pen = new Pen(Color.LightCoral, float.Parse("0.1"));
//Ecg_Pen = new Pen(Color.Black, float.Parse("0.1"));
bool shuxianFlag = false;
double PointCountPerMM = Math.Abs(double.Parse(Dpi.ToString()) / LenthPerInch);
int x = 0;
int y = 0;
for (int p = 0; p < Ecg_Canvas.Height / PointCountPerMM; p++)
{
for (int R = 0; R < Ecg_Canvas.Width / PointCountPerMM; R++)
{
if (x % 5 == 0 && !shuxianFlag)
{
Ecg_Graphics.DrawLine(Ecg_Pen, x, 0, x, Ecg_Canvas.Height);
}
x += int.Parse(Math.Round(double.Parse(PointCountPerMM.ToString("0.0"))).ToString());
if (x < Ecg_Canvas.Width && y < Ecg_Canvas.Height)
{
Ecg_Canvas.SetPixel(x, y, Color.Black);
}
else
{
x = 0;
break;
}
}
shuxianFlag = true;
if (y % 5 == 0)
{
Ecg_Graphics.DrawLine(Ecg_Pen, 0, y, Ecg_Canvas.Width, y);
}
y += int.Parse(Math.Round(double.Parse(PointCountPerMM.ToString("0.0"))).ToString());
if (y > Ecg_Canvas.Height)
{
break;
}
}
}
/// <summary>
/// 绘制心电图的背景网格
/// </summary>
public void Draw_EcgBackGroundGrid(int height1,int height2,int PenWidth)
{
if (PenWidth == 0)
Ecg_Pen = new Pen(Color.LightCoral, float.Parse("0.1"));
else
Ecg_Pen = new Pen(Color.Black, float.Parse("1"));
//Ecg_Pen = new Pen(Color.Black, PenWidth);
bool shuxianFlag = false;
double PointCountPerMM = Math.Abs(double.Parse(Dpi.ToString()) / LenthPerInch);
height1 = height1 * (int)PointCountPerMM;
height2 = height2 * (int)PointCountPerMM;
int x = 0;
int y = 0;
for (int p = 0; p < Ecg_Canvas.Height / PointCountPerMM; p++)
{
for (int R = 0; R < Ecg_Canvas.Width / PointCountPerMM; R++)
{
if (x % 5 == 0 && !shuxianFlag)
{
//Ecg_Graphics.DrawLine(Ecg_Pen, x, 0, x, Ecg_Canvas.Height);
Ecg_Graphics.DrawLine(Ecg_Pen, x, height1, x, height2);
}
x += int.Parse(Math.Round(double.Parse(PointCountPerMM.ToString("0.0"))).ToString());
if (x < Ecg_Canvas.Width && y < Ecg_Canvas.Height)
{
if (y >= height1 && y <= height2)
Ecg_Canvas.SetPixel(x, y, Color.Black);
//Ecg_Canvas.SetPixel(x, y, Color.LightCoral);
}
else
{
x = 0;
break;
}
}
shuxianFlag = true;
if (y % 5 == 0)
{
if (y >= height1 && y <= height2)
Ecg_Graphics.DrawLine(Ecg_Pen, 0, y, Ecg_Canvas.Width, y);
}
y += int.Parse(Math.Round(double.Parse(PointCountPerMM.ToString("0.0"))).ToString());
if (y > Ecg_Canvas.Height)
{
break;
}
}
}
/// <summary>
/// 绘制心电图的大网格 5mm大网格
/// </summary>
public void Draw_BigGrid()
{
Ecg_Pen = new Pen(Color.LightCoral, float.Parse("0.1"));
bool shuxianFlag = false;
double PointCountPerMM = Math.Abs(double.Parse(Dpi.ToString()) / LenthPerInch);
int x = 0;
int y = 0;
for (int p = 0; p < Ecg_Canvas.Height / PointCountPerMM; p++)
{
for (int R = 0; R < Ecg_Canvas.Width / PointCountPerMM; R++)
{
if (x % 5 == 0 && !shuxianFlag)
{
Ecg_Graphics.DrawLine(Ecg_Pen, x, 0, x, Ecg_Canvas.Height);
}
x += int.Parse(Math.Round(double.Parse(PointCountPerMM.ToString("0.0"))).ToString());
if (x < Ecg_Canvas.Width && y < Ecg_Canvas.Height)
{
//Ecg_Canvas.SetPixel(x, y, Color.LightCoral);
}
else
{
x = 0;
break;
}
}
shuxianFlag = true;
if (y % 5 == 0)
{
Ecg_Graphics.DrawLine(Ecg_Pen, 0, y, Ecg_Canvas.Width, y);
}
y += int.Parse(Math.Round(double.Parse(PointCountPerMM.ToString("0.0"))).ToString());
if (y > Ecg_Canvas.Height)
{
break;
}
}
}
/// <summary>
/// 绘制心电图的定标电压和导联名称
/// </summary>
public void Draw_CalibrationVoltage_And_LeadName()
{
Ecg_Pen = new Pen(Color.Black, float.Parse("1.5"));
string[] LeadNameArray = new string[12] { "I", "II", "III", "aVR", "aVL", "aVF", "V1", "V2", "V3", "V4", "V5", "V6" };
for (int d = 0; d < LeadInfo.Count; d++)
{
if (d < 6)
{
Ecg_Graphics.DrawLine(Ecg_Pen, 0, FirstPointArray[LeadInfo[d].ToString()].Y, Int16.Parse(Math.Round(double.Parse(FreePixs.ToString()) / 3).ToString()), FirstPointArray[LeadInfo[d].ToString()].Y);
Ecg_Graphics.DrawLine(Ecg_Pen, Int16.Parse(Math.Round(double.Parse(FreePixs.ToString()) / 3).ToString()), FirstPointArray[LeadInfo[d].ToString()].Y, Int16.Parse(Math.Round(double.Parse(FreePixs.ToString()) / 3).ToString()), FirstPointArray[LeadInfo[d].ToString()].Y - Int16.Parse(Math.Round(double.Parse(FreePixs.ToString()) * 2).ToString()));
Ecg_Graphics.DrawLine(Ecg_Pen, Int16.Parse(Math.Round(double.Parse(FreePixs.ToString()) / 3).ToString()), FirstPointArray[LeadInfo[d].ToString()].Y - Int16.Parse(Math.Round(double.Parse(FreePixs.ToString()) * 2).ToString()), Int16.Parse(Math.Round(double.Parse(FreePixs.ToString()) / 3).ToString()) * 2, FirstPointArray[LeadInfo[d].ToString()].Y - Int16.Parse(Math.Round(double.Parse(FreePixs.ToString()) * 2).ToString()));
Ecg_Graphics.DrawLine(Ecg_Pen, Int16.Parse(Math.Round(double.Parse(FreePixs.ToString()) / 3).ToString()) * 2, FirstPointArray[LeadInfo[d].ToString()].Y - Int16.Parse(Math.Round(double.Parse(FreePixs.ToString()) * 2).ToString()), Int16.Parse(Math.Round(double.Parse(FreePixs.ToString()) / 3).ToString()) * 2, FirstPointArray[LeadInfo[d].ToString()].Y);
Ecg_Graphics.DrawLine(Ecg_Pen, Int16.Parse(Math.Round(double.Parse(FreePixs.ToString()) / 3).ToString()) * 2, FirstPointArray[LeadInfo[d].ToString()].Y, Int16.Parse(Math.Round(double.Parse(FreePixs.ToString()) / 3).ToString()) * 3, FirstPointArray[LeadInfo[d].ToString()].Y);
string str = LeadNameArray[LeadInfo[d]];
Font font = new Font("宋体", 11);
Brush brush = Brushes.Black;
if (d < FirstPointArray.Count)
{
PointF point = new PointF(0, FirstPointArray[LeadInfo[d].ToString()].Y);
Ecg_Graphics.DrawString(str, font, brush, point);
}
}
else
{
Ecg_Graphics.DrawLine(Ecg_Pen, Ecg_Canvas.Width / 2, FirstPointArray[LeadInfo[d].ToString()].Y, Ecg_Canvas.Width / 2+Int16.Parse(Math.Round(double.Parse(FreePixs.ToString()) / 3).ToString()), FirstPointArray[LeadInfo[d].ToString()].Y);
Ecg_Graphics.DrawLine(Ecg_Pen, Ecg_Canvas.Width / 2 + Int16.Parse(Math.Round(double.Parse(FreePixs.ToString()) / 3).ToString()), FirstPointArray[LeadInfo[d].ToString()].Y, Ecg_Canvas.Width / 2 + Int16.Parse(Math.Round(double.Parse(FreePixs.ToString()) / 3).ToString()), FirstPointArray[LeadInfo[d].ToString()].Y - 2 * FreePixs);
Ecg_Graphics.DrawLine(Ecg_Pen, Ecg_Canvas.Width / 2 + Int16.Parse(Math.Round(double.Parse(FreePixs.ToString()) / 3).ToString()), FirstPointArray[LeadInfo[d].ToString()].Y - 2 * FreePixs, Ecg_Canvas.Width / 2 + Int16.Parse(Math.Round((double.Parse(FreePixs.ToString()) / 3)*2).ToString()), FirstPointArray[LeadInfo[d].ToString()].Y - 2 * FreePixs);
Ecg_Graphics.DrawLine(Ecg_Pen, Ecg_Canvas.Width / 2 + Int16.Parse(Math.Round((double.Parse(FreePixs.ToString()) / 3) * 2).ToString()), FirstPointArray[LeadInfo[d].ToString()].Y - 2 * FreePixs, Ecg_Canvas.Width / 2 + Int16.Parse(Math.Round((double.Parse(FreePixs.ToString()) / 3) * 2).ToString()), FirstPointArray[LeadInfo[d].ToString()].Y);
Ecg_Graphics.DrawLine(Ecg_Pen, Ecg_Canvas.Width / 2 + (FreePixs / 3) * 2, FirstPointArray[LeadInfo[d].ToString()].Y, Ecg_Canvas.Width / 2 + FreePixs, FirstPointArray[LeadInfo[d].ToString()].Y);
string str = LeadNameArray[LeadInfo[d]];
Font font = new Font("宋体", 11);
Brush brush = Brushes.Black;
if (d < FirstPointArray.Count)
{
PointF point = new PointF(Ecg_Canvas.Width / 2, FirstPointArray[LeadInfo[d].ToString()].Y);
Ecg_Graphics.DrawString(str, font, brush, point);
}
}
}
}
/// <summary>
/// 获得心电数据
/// </summary>
/// <returns></returns>
public Dictionary<int, List<double>> GetEcgData(DataTable EcgDataTable)
{
string[] WavePara = File.ReadAllText(Application.StartupPath + @"\WavePara.txt").Trim().Split(',');
SamplingRate = int.Parse(WavePara[0].Trim());
AmplificationFactor = double.Parse(WavePara[1].Trim());
Dictionary<int, List<double>> get_EcgDataList = new Dictionary<int, List<double>>();
for (int y = 0; y < EcgDataTable.Rows.Count; y++)
{
byte[] ecgdata = (byte[])EcgDataTable.Rows[y]["pureData"];
Int16[,] ecg = new Int16[LeadCount, ecgdata.Length / (LeadCount * byteLength)];
Int16[,] EcgPixData = new Int16[LeadCount, ecgdata.Length / (LeadCount * byteLength)];
int index = 0;
for (int q = 0; q < LeadCount; q++)
{
for (int i = 0; i < SamplingRate*5; i++)
{
byte a = ecgdata[index];
index++;
byte b = ecgdata[index];
index++;
ecg[q, i] = (Int16)(a + (b << 8));
string sss = ((double.Parse(ecg[q, i].ToString()) / AmplificationFactor) * 10.0).ToString();
double cc = double.Parse(sss) * double.Parse(Dpi.ToString()) / double.Parse(LenthPerInch.ToString());
if (get_EcgDataList.ContainsKey(q))
get_EcgDataList[q].Add(cc);
//get_EcgDataList[q].Add(short.Parse(cc.ToString()));
else
{
short f = (short)cc;
List<double> ecg_List = new List<double>();
ecg_List.Add((double)f);
//ecg_List.Add(short.Parse(cc.ToString()));
get_EcgDataList.Add(q, ecg_List);
}
}
}
}
return get_EcgDataList;
}
/// <summary>
/// 获得心电数据
/// </summary>
/// <returns></returns>
public Dictionary<int, List<float>> GetEcgData(DataTable EcgDataTable,bool ReturnFloat)
{
string[] WavePara = File.ReadAllText(Application.StartupPath + @"\WavePara.txt").Trim().Split(',');
SamplingRate = int.Parse(WavePara[0].Trim());
AmplificationFactor = double.Parse(WavePara[1].Trim());
Dictionary<int, List<float>> get_EcgDataList = new Dictionary<int, List<float>>();
for (int y = 0; y < EcgDataTable.Rows.Count; y++)
{
byte[] ecgdata = (byte[])EcgDataTable.Rows[y]["pureData"];
Int16[,] ecg = new Int16[LeadCount, ecgdata.Length / (LeadCount * byteLength)];
Int16[,] EcgPixData = new Int16[LeadCount, ecgdata.Length / (LeadCount * byteLength)];
int index = 0;
for (int q = 0; q < LeadCount; q++)
{
for (int i = 0; i < SamplingRate*5; i++)
{
byte a = ecgdata[index];
index++;
byte b = ecgdata[index];
index++;
ecg[q, i] = (Int16)(a + (b << 8));
double sss = double.Parse(ecg[q, i].ToString()) / AmplificationFactor;
float resulte_cc = (float)sss;
//double cc = double.Parse(sss) * double.Parse(Dpi.ToString()) / double.Parse(LenthPerInch.ToString());
if (get_EcgDataList.ContainsKey(q))
get_EcgDataList[q].Add(resulte_cc);
//get_EcgDataList[q].Add(short.Parse(cc.ToString()));
else
{
List<float> ecg_List = new List<float>();
ecg_List.Add(resulte_cc);
get_EcgDataList.Add(q, ecg_List);
}
}
}
}
return get_EcgDataList;
}
///// <summary>
///// 波形放大或缩小
///// </summary>
//public void AmplifyOrLessen(int OptionParameter)
//{
// // double a = Math.Abs(double.Parse(Dpi.ToString()) / LenthPerInch) * OptionParameter;
// // int WaveAmplify = (int)a;
// Ecg_Pen = new Pen(Color.Black, float.Parse("0.5"));
// for (int i = 0; i < LeadInfo.Count; i++)
// {
// int LeadIndex = LeadInfo[i];//取导联下标 0 1 2 3 ...11
// BaseLine = (Ecg_Canvas.Height / LeadInfo.Count) / 2 + (i * LeadHeight);
// FirstPosition.Y = BaseLine;
// FirstPosition.X = FreePixs;
// SecondPosition.Y = BaseLine;
// SecondPosition.X = FreePixs;
// Point FP = new Point(FirstPosition.X + FreePixs, FirstPosition.Y);
// FirstPointArray.Add(LeadIndex.ToString(), FP);
// for (int b = 0; b < EcgDataList[LeadIndex].Count; b++)
// {
// if (FirstPosition.X > Ecg_Canvas.Width)
// break;
// if (EcgDataList[LeadIndex][b] > 0)
// SecondPosition.Y = Math.Abs(BaseLine - EcgDataList[LeadIndex][b]) + OptionParameter;
// if (EcgDataList[LeadIndex][b] < 0)
// SecondPosition.Y = BaseLine + Math.Abs(EcgDataList[LeadIndex][b]) + OptionParameter;
// double x = double.Parse(b.ToString()) * (double.Parse(Dpi.ToString()) / double.Parse(SamplingRate.ToString())) * (PaperSpeed * OptionParameter)/Amplitude;//获得点的X轴位置
// int nextX = (int.Parse(Math.Round(x).ToString()));
// if (Math.Abs(FirstPosition.X - SecondPosition.X) < 5)
// {
// SecondPosition.X = nextX + FreePixs;
// Ecg_Graphics.DrawLine(Ecg_Pen, FirstPosition, SecondPosition);
// FirstPosition = SecondPosition;
// }
// else
// FirstPosition = SecondPosition;
// }
// }
//}
//**************************动态播放十二导联波形************************************************************************************
/// <summary>
/// 绘制屏幕墙窗体背景
/// </summary>
/// <param name="Graphics"></param>
public void DrawBackGround(Graphics Graphics)
{
Graphics.FillRectangle(Brushes.White, Graphics.ClipBounds);
}
public void DrawStandardGrid(PictureBox EV, Graphics Graphics)
{
int GridSize = int.Parse((Math.Round(double.Parse("96") * double.Parse("5") / double.Parse("25.4"))).ToString());
Pen GridColor = new Pen(Color.LightCoral, float.Parse("0.1"));
//绘制网格大格竖线
for (int i = 0; i < EV.Width; i += GridSize)
{
Graphics.DrawLine(GridColor, i, 0, i, EV.Height);
}
//绘制网格大格横线
for (int i = 0; i < EV.Height; i += GridSize)
{
Graphics.DrawLine(GridColor, 0, i, EV.Width, i);
}
}
DateTime CurrentDateTime;
string V_WardshipId = string.Empty;
int Ecg_Index = 0;//数据队列中的游标
double PixCountPerPoint;//求出 心电 相邻两点之间的 像素点个数
/// <summary>
/// 绘制心电波形
/// </summary>
//public void Play_EcgWave(PictureEdit pictureEdit3, Graphics Graphics_1, string WardshipId, DateTime CurrDatetime)
//{
// PixCountPerPoint = double.Parse("0.3");
// V_WardshipId = WardshipId;
// if (CurrDatetime != null)
// CurrentDateTime = CurrDatetime;
// Ecg_Pen = new Pen(Color.Black, float.Parse("0.5"));//心电波形颜色
// FirstPointArray.Clear();
// LeadHeight = pictureEdit3.Height / LeadInfo.Count;
// FreePixs = int.Parse(Math.Round((double.Parse(Dpi.ToString()) / LenthPerInch) * 5).ToString());
// for (int i = 0; i < LeadInfo.Count; i++)
// {
// int LeadIndex = LeadInfo[i];//取导联下标 0 1 2 3 ...11
// BaseLine = (pictureEdit3.Height / LeadInfo.Count) / 2 + (i * LeadHeight);
// FirstPosition.Y = BaseLine;
// FirstPosition.X = FreePixs;
// SecondPosition.Y = BaseLine;
// SecondPosition.X = FreePixs;
// Point FP = new Point(FirstPosition.X + FreePixs, FirstPosition.Y);
// FirstPointArray.Add(LeadIndex.ToString(), FP);
// int ScreenPointCount = (int)(double.Parse(pictureEdit3.Width.ToString()) / PixCountPerPoint);
// for (int b = Ecg_Index; b < Ecg_Index + ScreenPointCount; b++)
// {
// if (EcgDataList == null)
// LoadEcgData_BaseDatabase(WardshipId);//加载心电数据队列
// else
// if (EcgDataList[LeadIndex].Count <= 0 || b + 500 >= EcgDataList[LeadIndex].Count)
// LoadEcgData_BaseDatabase(WardshipId);//加载心电数据队列
// if (b + 1 >= EcgDataList[LeadIndex].Count)
// {
// Graphics_1.DrawLine(new Pen(Brushes.Black), 0, pictureEdit3.Height / 2, pictureEdit3.Width, pictureEdit3.Height / 2);
// }
// else
// {
// if (FirstPosition.X > pictureEdit3.Width)
// break;
// if (EcgDataList[LeadIndex][b] > 0)
// SecondPosition.Y = Math.Abs(BaseLine - EcgDataList[LeadIndex][b]);
// if (EcgDataList[LeadIndex][b] < 0)
// SecondPosition.Y = BaseLine + Math.Abs(EcgDataList[LeadIndex][b]);
// double x = double.Parse(b.ToString()) * (double.Parse(Dpi.ToString()) / double.Parse(SamplingRate.ToString()));//获得点的X轴位置
// int nextX = (int.Parse(Math.Round(x).ToString()));
// if (Math.Abs(FirstPosition.X - SecondPosition.X) < 5)
// {
// SecondPosition.X = nextX + FreePixs;
// //Ecg_Graphics.DrawLine(Ecg_Pen, FirstPosition, SecondPosition);
// Graphics_1.DrawLine(Ecg_Pen, FirstPosition, SecondPosition);
// FirstPosition = SecondPosition;
// }
// else
// FirstPosition = SecondPosition;
// }
// }
// }
// Ecg_Index += 14;
//}
}
}