FrmCameraPlay.cs
5.5 KB
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
using AccAOI.camera;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using TSA_V.Common;
using TSA_V.DeviceLibrary;
namespace TSA_V
{
public partial class FrmCameraPlay : Form
{
public bool ISShow = false;
public int ScreenIndex = ConfigAppSettings.GetIntValue(Setting_Init.VideoFrom_Index, 2);
public bool NeedShow = ConfigAppSettings.GetBoolValue(Setting_Init.VideoForm_Show);
public static FrmCameraPlay instance = new FrmCameraPlay();
public FrmCameraPlay()
{
//NeedShow = false;
InitializeComponent();
}
private void FrmCameraPlay_Load(object sender, EventArgs e)
{
}
public bool ShowForm()
{
ISShow = true;
if (!NeedShow)
{
return false;
}
Screen[] sc = Screen.AllScreens;
Screen screen = null;
if (sc.Count() > ScreenIndex)
{
screen = sc[ScreenIndex];
int ScreenWidth = screen.Bounds.Width;
int ScreenHeight = screen.Bounds.Height;
this.Width = ScreenWidth;
this.Height = ScreenWidth;
this.StartPosition = FormStartPosition.Manual;
this.WindowState = FormWindowState.Maximized;
this.Location = new Point(0, 0);
this.ShowDialog();
LogUtil.info("实时视频界面显示:屏幕索引=" + ScreenIndex + " !");
return true;
}
else if (sc.Count() > 0)
{
screen = sc[0];
this.StartPosition = FormStartPosition.Manual;
this.Size = new Size(400, 300);
this.Location = new Point(screen.Bounds.Left + screen.Bounds.Width - this.Width, screen.Bounds.Top + 5);
this.ShowDialog();
LogUtil.info("实时视频界面显示:屏幕索引=" + ScreenIndex + " !");
return true;
}
else
{
LogUtil.info("实时视频界面显示:屏幕索引=" + ScreenIndex + " 未找到");
return false;
}
}
private void FrmCameraPlay_Shown(object sender, EventArgs e)
{
timer1.Start();
this.TopMost = true;
CameraManager.camera_event += CameraManager_camera_event;
CameraManager.LoadCamera();
CameraManager.StartGetImage(CameraName());
//CameraManager.LoadCamera();
//HIKCamera.Instance.camera_event += CameraManager_camera_event;
//CameraManager.StartCallBackGrabImage(CameraName());
}
private void CameraManager_camera_event(object sender, Bitmap e)
{
try
{
if (e != null)
{
if (pictureBox1.Image != null)
{
pictureBox1.Image.Dispose();
}
pictureBox1.Image = e;
}
}
catch (Exception ex)
{
LogUtil.error("CameraManager_camera_event 出错:" + ex.ToString());
}
}
private string CameraName()
{
string camera = ConfigAppSettings.GetValue(Setting_Init.CameraName);
if (camera == "")
{
camera = AccAOI.camera.CameraManager.hikNameList.ToArray().FirstOrDefault();
}
return camera;
}
private void timer1_Tick(object sender, EventArgs e)
{
if(this.Visible )
{
try
{
//string camera = ConfigAppSettings.GetValue(Setting_Init.CameraName);
//if (camera == "")
//{
// camera = AccAOI.camera.CameraManager.hikNameList.ToArray().FirstOrDefault();
//}
//Image currImage = CameraManager.GetCamerImage(camera);
//if (currImage == null)
//{
// string file = @"G:\test.bmp";
// if (File.Exists(file))
// {
// //从本地加载图片
// Bitmap aa = new Bitmap(file);
// currImage = ImageManager.DeepClone(aa);
// }
//}
//if (currImage != null)
//{
// if (pictureBox1.Image != null)
// {
// pictureBox1.Image.Dispose();
// }
// pictureBox1.Image = currImage;
//}
}
catch (Exception ex)
{
LogUtil.error("实时视频播放出错:" + ex.ToString());
}
}
}
private void FrmCameraPlay_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = true;
}
private void FrmCameraPlay_FormClosed(object sender, FormClosedEventArgs e)
{
CameraManager.StopGetImage();
}
}
}