BoxBean_Camera.cs
1.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
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace OnlineStore.DeviceLibrary
{
partial class BoxBean
{
Thread camerathread;
Asa.HIK.IPCamera camera;
public event EventHandler<Bitmap> camera_event;
void LoadCameraConfig(string id) {
string path = @".\StoreConfig\box_"+id+"_Camera.json";
if (!File.Exists(path))
{
LogUtil.error(Name + "找不到监控相机配置文件"+ path);
}
camera = new Asa.HIK.IPCamera(path);
bool rtn = camera.Load();
if (!rtn)
LogUtil.error(Name + "加载监控相机配置文件失败");
camerathread = new Thread(new ThreadStart(startCamera));
camerathread.Start();
//pictureBox1.Image = bmp;
}
void startCamera() {
var rtn = camera.Open(0);
if (!rtn)
LogUtil.error(Name + "打开监控相机失败");
while (camera.IsOpen[0])
{
rtn = camera.GrabOne(0, out Bitmap bmp);
if (rtn)
{
camera_event?.Invoke(this, bmp);
}
Thread.Sleep(1000/10);
}
camera.Close(0);
camera.Dispose();
}
}
}