1 /// <summary>
2 /// 获得ICogImage图像格式
3 /// </summary>
4 /// <param name="imagepath"></param>
5 /// <returns></returns>
6 private ICogImage GetImage(string imagepath)
7 {
8 if (!File.Exists(imagepath))
9 return null;
10 CogImageFile ImageFile1 = new CogImageFile();
11 ICogImage Image;
12 ImageFile1.Open(imagepath, CogImageFileModeConstants.Read);
13 Image = ImageFile1[0];
14 ImageFile1.Close();
15 return Image;
16 }
17
18 /// <summary>
19 /// 原图像保存
20 /// </summary>
21 /// <param name="display"></param>
22 /// <param name="path"></param>
23 private void SaveOrignalImage(CogRecordDisplay display, string path)
24 {
25 try
26 {
27 if (!Directory.Exists(path))
28 {
29 Directory.CreateDirectory(path);
30 }
31
32 string filename = "_" + DateTime.Now.ToString("HHmmssff") + "_" + ".bmp";
33
34 ICogImage orignalImage = display.Image;
35 CogImageFile ImageFile = new CogImageFile();
36 ImageFile.Open(path + "\\" + filename, CogImageFileModeConstants.Write);
37 ImageFile.Append(orignalImage);
38 ImageFile.Close();
39 }
40 catch (Exception ex)
41 {
42 Log.WriteTxt("保存图像出现错误:" + ex.Message);
43
44 }
45
46 }
47
48 /// <summary>
49 /// 保存图像截图
50 /// </summary>
51 /// <param name="display"></param>
52 /// <param name="path"></param>
53 private void SaveScreenImage(CogRecordDisplay display, string path) //保存界面截图jpeg
54 {
55 try
56 {
57 // path = path + "\\" + "Camera-" + index.ToString();
58 if (!System.IO.Directory.Exists(path))
59 {
60 System.IO.Directory.CreateDirectory(path);
61 }
62
63 string filename = "_" + DateTime.Now.ToString("HHmmssff") + "_" + ".jpg";
64 Bitmap bmp = display.CreateContentBitmap(CogDisplayContentBitmapConstants.Image) as Bitmap;
65 // Bitmap bmp = display.Image.ToBitmap();
66 bmp.Save(path + "\\" + filename, System.Drawing.Imaging.ImageFormat.Jpeg);
67 }
68 catch (Exception ex)
69 {
70 Log.WriteTxt("保存处理图像出现错误,信息为" + ex.Message);
71 }
72 }
73
74 /// <summary>
75 /// 将图像转换成CogImage8Grey
76 /// </summary>
77 /// <param name="imagepath">路径</param>
78 /// <returns></returns>
79 private CogImage8Grey GetSimulateImage(string imagepath)
80 {
81 if (File.Exists(imagepath))
82 return null;
83 CogImageFile ImageFile1 = new CogImageFile();
84 CogImage8Grey Image;
85 ImageFile1.Open(imagepath, CogImageFileModeConstants.Read);
86 Image = (CogImage8Grey)ImageFile1[0];
87 ImageFile1.Close();
88 return Image;
89 }