记录

贝克曼的血球真是让人很无语,首先厂商傲娇不给支持,文档跟天书似的,不能出图又要被医院吐槽技术不行什么的。为了他的图也是费尽心思啊(碰到了就自求多福吧,哈哈)。分享一下解析逻辑,碰到这种事的小伙伴少走点弯路。先欣赏一波仪器文档。

直方图还能稍稍理解一下

数据图(这是内部人员自己的笔记吧)

 

 

 

 

经过各种找资料试啊终于解析出来了

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">
/// [功能描述:LH780出图] <para/>
/// [创建者:zlz] <para/>
/// [创建时间:2018年01月31日] <para/>
///<说明>
/// [说明:[功能描述:LH780出图]<para/>
///</说明>
///<修改记录>
/// [修改时间:本次修改时间]<para/>
/// [修改内容:本次修改内容]<para/>
///</修改记录>
///<修改记录>
/// [修改时间:本次修改时间]<para/>
/// [修改内容:本次修改内容]<para/>
/// M端触发代码,其他的和监听程序一样,直方图多条线用#分割数据
/// s retObj=##Class(wbsLisMsgAsyncHandler.LISMsg.wbsLisDrawImageAsyncHandlerSoap).%New()
/// s ret=retObj.DrawImage("1","绘图数据","仪器","处理M","传输次数","其他参数","LIS.Mach.ImageDeal.ImageDealTest,LIS.Mach.ImageDeal")
/// s ret=$$DealImage^MI.MIF000(epis,"RBC绘图数据串",mi,"和监听一样的有保存图片的M类","-1","Histogram#RBCH.bmp#######10#10#320#138","LIS.Mach.ImageDeal.ImageDealLH780,LIS.Mach.ImageDeal")
/// s ret=$$DealImage^MI.MIF000(epis,"PLT绘图数据串",mi,"和监听一样的有保存图片的M类","-1","Histogram#PLT.bmp#######10#10#320#138","LIS.Mach.ImageDeal.ImageDealLH780,LIS.Mach.ImageDeal")
/// s ret=$$DealImage^MI.MIF000(epis,"WBC绘图数据串",mi,"和监听一样的有保存图片的M类","-1","Histogram#WBCF.bmp#######10#10#320#138","LIS.Mach.ImageDeal.ImageDealLH780,LIS.Mach.ImageDeal")
/// s ret=$$DealImage^MI.MIF000(epis,"WBC绘图数据串",mi,"和监听一样的有保存图片的M类","-1","DiffPlot#DIFF.bmp#######10#10#320#138","LIS.Mach.ImageDeal.ImageDealLH780,LIS.Mach.ImageDeal")
///</修改记录>
///</summary>
public class ImageDealLH780 : 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)
{
int cunt = 0;
try
{
//string epis = row["Epis"].ToString();
//1.1从其他参数中获取所需要的参数
string[] paraList = otherPara.Split('#');
string graphType = "";
string imgClass = "";
string label = "";
string title = "";
string maxDot = "";
string maxValue = "";
string memo = "";
string foreColor = "";
string top = "";
string left = "";
string width = "";
string height = "";
if (paraList.Length > 1)
{
graphType = paraList[0];
imgClass = paraList[1];
}
else
{
return true;
}
if (paraList.Length > 11)
{
title = paraList[2];
label = paraList[3];
maxDot = paraList[4];
maxValue = paraList[5];
memo = paraList[6];
foreColor = paraList[7];
top = paraList[8];
left = paraList[9];
width = paraList[10];
height = paraList[11];

}
//#2.1校验必要参数是否存在
if (String.IsNullOrEmpty(width))
{
width = "320";
}
if (String.IsNullOrEmpty(height))
{
height = "138";
}

if (String.IsNullOrEmpty(foreColor))
{
foreColor = "0";
}
//#2.2取得画图所需要的元素
double imageWidth = Convert.ToDouble(width);
double imageHeight = Convert.ToDouble(height);

//#2.3分不同类型的图形来进行绘图
//画直方图
if (graphType == "Histogram")
{
string[] resArr = result.Split('#');
Bitmap image = null;
for (int zi = 0; zi < resArr.Length; zi++)
{
result=resArr[zi];
if (result == "")
{
continue;
}
float[] dot = new float[result.Length / 2];
float imgMaxValue = 0;
int indexD = 0;
for (int i = 0; i < result.Length - 2; i = i + 2)
{
dot[indexD] = Convert.ToInt32(result[i] + "", 16) * 16 + Convert.ToInt32(result[i + 1] + "", 16);
if (dot[indexD] > imgMaxValue)
{
imgMaxValue = dot[indexD];
}
indexD++;
}

//没传背景画普通的
if (imgClass == "")
{
Histogram histogram = new Histogram(label, title, dot.Length, imgMaxValue, foreColor, Convert.ToInt32(width), Convert.ToInt32(height));
histogram.Values = dot;
image = histogram.CreateImage();
}
//传了特殊画
else
{
image = CreateImage(imgClass, imgMaxValue, dot, image);
}
}
//判断C盘trak是否存在
string tmpPath = @"c:\TRAK\tmpMach";
if (!Directory.Exists("C:\\TRAK"))
{
Directory.CreateDirectory("C:\\TRAK"); //新建文件夹
if (!Directory.Exists(tmpPath))
{
Directory.CreateDirectory(tmpPath); //新建文件夹
}
}
//先删除临时目录里面的所有文件
DeleteFolder(tmpPath);
image.Save(tmpPath + "\\" + imgClass.Replace(".bmp","") + epis + ".bmp");
image.Dispose();
string ftpPath = "";
FtpService ftp = GetFtpHelper(machID, dealProcess, out ftpPath);
上传图片
ftp.Upload(tmpPath + "\\" + imgClass.Replace(".bmp", "") + epis + ".bmp");
//保存图片
SaveImg(machID, epis, imgClass.Replace(".bmp", ""), ftpPath.Split('^')[3] + imgClass.Replace(".bmp", "") + epis + ".bmp", dealProcess);
File.Delete(tmpPath + "\\" + imgClass.Replace(".bmp", "") + epis + ".bmp");
}
else if (graphType == "DiffPlot")
{

string renderingData = "00000000000000000000000000000000000000000000000000000000000000010000000000000000000000020100000100000000000000000000000100000102010000010000000000000201000001010100000102000001000000010200010101000101010000010000020102000101010102010100010101000101010101020101010101000101010001010101010201010101010100010101010101010101010101010101000000000000000000000000000000000000000000000000000300000000000000000000000304000004000000000000000000000003000003040300000300000000000003030000030403000003040000030000000304000304030003030300000300000303040003040303030303000303030003030303030403030303040003030300040303030303030303030304030303030303030303030303030303030000000000000000000000000000000000000000000000000005000000000000000000000004050000050000000000000000000000050000050604000004000000000000040500000506050000050400000500000005040005060500040505000005000004050500050605050505040006050500050605050605060505050500060505000605060505060506060506050606060606060606060606060606060600000000000000000000000000000000000000000000000000070000000000000000000000070800000700000000000000000000000700000708070000070000000000000708000008070800000807000008000000080700080708000807080000080000080807000807080808080700080809000808070808090808080808000808080008080808080808080808080808080808080808080808080808080808000000000000000000000000000000000000000000000000000A0000000000000000000000070A00000A00000000000000000000000A00000A070A00000A000000000000020A00000A070A00000A0200000A0000000A0700070A0A000A0A0A00000A00000A0A0A000A0A0A0A0A0A0A000A000A00000A000A0A000A00000A000A0A000A00000A000A0A000A00000A000A0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B00000000000000000000000000000000000000000000000000030000000000000000000000030B0000020000000000000000000000030000020B0B000002000000000000030B00000203020000020B00000B0000000B030002030200020C0B00000200000B030B00020302020B020B00020B02000B0302020203030B0B020B000B0202000203030B03030B02020B02030B03030B020B02020B02030B030B0B030008";
if (renderingData.Length < 1920)
{
LIS.Core.Util.LogUtils.WriteExceptionLog("绘制散点图失败", new Exception("渲染数据数据不能少于60x32"));
return false;
}
if (result.Length < 8160)
{
LIS.Core.Util.LogUtils.WriteExceptionLog("绘制散点图失败", new Exception("数据少于8160"));
return false;
}
List<string> renderList = new List<string>();
for (int z = 0; z < 60; z++)
{
renderList.Add(renderingData.Substring(z * 32, 32));
}
int leftInt = 0;
int topInt = 0;
int curX = leftInt;
int curY = topInt;
int imgWidth = 255;
StringBuilder dataplotBlock = new StringBuilder();
Bitmap img = null;
//#1.2获得画图句柄
Graphics g = null;
Image imgtmp = Image.FromStream(GetImageStram(imgClass)) as Bitmap;
img = new Bitmap(imgtmp.Width, imgtmp.Height);
g = Graphics.FromImage(img);
g.Clear(Color.White);
//+抗锯齿
g.SmoothingMode = SmoothingMode.AntiAlias;
g.DrawImage(imgtmp, 0, 0, img.Width, img.Height);
Pen pen = new Pen(Color.Black);
for (int i = 0; i < result.Length-1; i += 2)
{
int renderingIndex = Convert.ToInt32(result[i] + "", 16) * 16 + Convert.ToInt32(result[i + 1] + "", 16);
if (renderingIndex >= renderList.Count)
{
continue;
}
for (int heightInt = 0; heightInt < 4; heightInt++)
{
for (int widthInt = 0; widthInt < 4; widthInt++)
{
int begin = (heightInt * 4 + widthInt) * 2;
string colorVal = renderList[renderingIndex].Substring(begin, 2);
string curColor = "";
if (colorVal == "00")
{
curColor = "#000000";
}
else if (colorVal == "01")
{
curColor = "#FFFFFF";
}
else if (colorVal == "02")
{
curColor = "#606060";
}
else if (colorVal == "03")
{
curColor = "#FF0000";
}
else if (colorVal == "04")
{
curColor = "#FFFF00";
}
else if (colorVal == "05")
{
curColor = "#FF00FF";
}
else if (colorVal == "06")
{
curColor = "#800080";
}
else if (colorVal == "07")
{
curColor = "#00FFFF";
}
else if (colorVal == "08")
{
curColor = "#00FF00";
}
else if (colorVal == "09")
{
curColor = "#008000";
}
else if (colorVal == "0A")
{
curColor = "#0000FF";
}
else if (colorVal == "0B")
{
curColor = "#000080";
}
else if (colorVal == "0C")
{
curColor = "#800000";
}
else if (colorVal == "0D")
{
curColor = "#808080";
}
else
{
curColor = "#000000";
}
if (curColor != "#000000")
{
if (curX + widthInt < img.Width && curY + heightInt < img.Height)
{
pen.Color = System.Drawing.ColorTranslator.FromHtml(curColor);
g.DrawEllipse(pen, curX + widthInt, curY + heightInt, 1, 1);
cunt++;
}
}
}
}
curX += 4;
if (curX > imgWidth)
{
curY += 4;
curX = leftInt;
}
}
//判断C盘trak是否存在
string tmpPath = @"c:\TRAK\tmpMach";
if (!Directory.Exists("C:\\TRAK"))
{
Directory.CreateDirectory("C:\\TRAK"); //新建文件夹
if (!Directory.Exists(tmpPath))
{
Directory.CreateDirectory(tmpPath); //新建文件夹
}
}
//先删除临时目录里面的所有文件
DeleteFolder(tmpPath);
img.Save(tmpPath + "\\" + imgClass.Replace(".bmp", "") + epis + ".bmp");
img.Dispose();
string ftpPath = "";
FtpService ftp = GetFtpHelper(machID, dealProcess, out ftpPath);
上传图片
ftp.Upload(tmpPath + "\\" + imgClass.Replace(".bmp", "") + epis + ".bmp");
//保存图片
SaveImg(machID, epis, imgClass.Replace(".bmp", ""), ftpPath.Split('^')[3] + imgClass.Replace(".bmp", "") + epis + ".bmp", dealProcess);
File.Delete(tmpPath + "\\" + imgClass.Replace(".bmp", "") + epis + ".bmp");
}
return true;
}
catch (Exception ex)
{
LIS.Core.Util.LogUtils.WriteExceptionLog("绘制H780图发生错误,数据串:" + result+" 其他参数:"+otherPara , ex);
return false;
}
}

/// 清空指定的文件夹,但不删除文件夹
/// </summary>
/// <param name="dir"></param>
public static void DeleteFolder(string dir)
{
foreach (string d in Directory.GetFileSystemEntries(dir))
{
if (File.Exists(d))
{
FileInfo fi = new FileInfo(d);
if ((DateTime.Now - fi.CreationTime).Minutes > 10)
{
if (fi.Attributes.ToString().IndexOf("ReadOnly") != -1)
{
fi.Attributes = FileAttributes.Normal;
}
File.Delete(d);//直接删除其中的文件
}
}
else
{
DirectoryInfo d1 = new DirectoryInfo(d);
if (d1.GetFiles().Length != 0)
{
DeleteFolder(d1.FullName);递归删除子文件夹
}
Directory.Delete(d);
}
}
}

/// <summary>
/// 获得图片流
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public Stream GetImageStram(string name)
{
return this.GetType().Assembly.GetManifestResourceStream("LIS.Mach.ImageDeal.Image." + name);
}

/// <summary>
/// 画图逻辑
/// </summary>
public Bitmap CreateImage(string bgName, float MaxValue, float[] Values, Bitmap imageold)
{
//#1.画坐标系,先简单画两条线,暂时不做细节
Bitmap img = null;
//#1.2获得画图句柄
Graphics g = null;
if (imageold != null)
{
img = imageold;
g = Graphics.FromImage(img);
}
else
{
Image imgtmp = Image.FromStream(GetImageStram(bgName)) as Bitmap;
img = new Bitmap(imgtmp.Width, imgtmp.Height);
g = Graphics.FromImage(img);
g.Clear(Color.White);
//+抗锯齿
g.SmoothingMode = SmoothingMode.AntiAlias;
g.DrawImage(imgtmp, 0, 0, img.Width, img.Height);
}

int Height = img.Height;
//#1.3偏移
int x = 1;
int y = 20;
//画横纵坐标线
Pen pen = new Pen(Color.Black);
pen.Width = 2;
//#3.开始进点的数据,进行绘图
double radix = (img.Width - 30)*1.0 / Values.Length;
if (Values.Length == 256)
{
radix = radix * 2;
}
float preY = -1;
int curindex = 0;
double radiy = 1;
if (MaxValue != 0)
{
radiy = (Height - 40)*1.0 / MaxValue;
}
foreach (var d in Values)
{
if (preY == -1)
{
pen = new Pen(Color.Black);
pen.Width = 1;
}
else
{
pen = new Pen(Color.Black);
pen.Width = 1;
if (10 + x * radix > img.Width)
{
continue;
}
if (Height - d * radiy - y > img.Height || Height - d * radiy - y<0)
{
continue;
}
g.DrawLine(pen, 10 + (int)(x * radix), Height - (int)(d * radiy) - y, 10 + (int)((x - 1) * radix), preY - y);
}
preY = Height - (int)(d * radiy);
x += 1;
curindex++;
}
return img;
}
}
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
直方图得到Y坐标逻辑(实际理解每两个字符用十六进制表示一个Y坐标)

解散点图逻辑部分(不知道什么意义,反正最后效果出来了)


效果

 

 

 

 

RBC数据

0405040302020101020202020101000000000102020202030406070A0E1014181E242B343F4A535E6B7B8B9BA9B5BEC5CCCCCBC6C0BAB3ACA0918274675A5149433B332A231E1A1716141211100F0F0F0F0F0F0F101010100F1010101010111211121111101010100F0F0F0F0E0E0E0D0C0B0A0B0B0B0A0909090807070706060605050505050606060605040302020201010202010101010101000000000000000001010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1
PLT数据

000000000003132F42566679859199A4B4C4C8C8C8CCCCC8C8C0B8B0ACA8A4A0A0A09C8D81756D66625E5A56524E463E36332F2F2B2B2B272327232723231F1F0F1B1F1B171B0B000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1
WBCF数据

000000000000000000000000000000000000663939332C261F191F26333F4C5F7999ACB8BFBFBFC5CCCCBFAC928C7F725F524639332C2C2C2C2C33332C33333333332C2C2C2C2C2C2C2C2C2C2C26261F1F1F1F1F1F1F1F1F19191913131319131313131313130C0C0C130C0C0C060606060C0C0C0C13131313130C0C13191919191919191F1F2626262626262C3339393F393F3F46464646464C5259595F5F666C6C6C666C6C72797F7F7F8C92928C7F8585857F797979797F7F7F726C6C6C7272797979726C665F5F5F5F5F5F5F5F5959595F5F594C463F3F393933332C261F1F1F1F261F191313191913131313131313130C0C06060C0C0606060000000000
1
散点图数据

0000000000000000000000000000000000000000000000000000000000000000150000000000000000000000000000000000000000000
————————————————
版权声明:本文为CSDN博主「Walk in loosing」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/zhanglianzhu_91/article/details/88773619

posted @ 2023-08-25 21:56  巴蒂青葱  阅读(15)  评论(0编辑  收藏  举报