UsrCamera.cs
3.4 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
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using Model;
namespace SmartScan
{
public partial class UsrCamera : UserControl, ISetMenu
{
private Bitmap bmp = null;
public UsrCamera()
{
InitializeComponent();
Asa.FaceControl.Language.SetLanguage(this);
BtnCameraImage.Enabled = Common.cameraVision==null?false:Common.cameraVision.Count > 0;
}
public Asa.FaceControl.FacePanel GetPanel()
{
return facePanel1;
}
public void Save() { }
private void BtnOpenLight_Click(object sender, EventArgs e)
{
Common.lightSource.TurnOn();
}
private void BtnCloseLight_Click(object sender, EventArgs e)
{
Common.lightSource.TurnOff();
}
private void BtnCameraImage_Click(object sender, EventArgs e)
{
Common.cameraVision.Open();
Bitmap[] result = Common.cameraVision.GetImage();
Common.cameraVision.Close();
if (result.Length == 0) return;
bmp = result[0];
LstCode.Items.Clear();
PicShow.CodeCenterClear();
PicShow.Image = bmp;
}
private void BtnLocalImage_Click(object sender, EventArgs e)
{
using OpenFileDialog dlg = new() { Filter = "Image Files|*.jpg;*.jpeg;*.png;*.bmp;*.gif|All Files|*.*" };
if (dlg.ShowDialog() != DialogResult.OK) return;
bmp = ObjConversion.ReadImageFile(dlg.FileName);
LstCode.Items.Clear();
PicShow.CodeCenterClear();
PicShow.Image = bmp;
}
private void BtnScanCode_Click(object sender, EventArgs e)
{
if (bmp == null) return;
List<CameraVisionLib.Model.BarcodeInfo> info = Common.cameraVision.GetBarCode(bmp);
LstCode.Items.Clear();
PicShow.CodeCenterClear();
if (info.Count == 0)
{
string text = Asa.FaceControl.Language.Dialog(Model.LanguageDialogKey.CODE_COUNT);
new Asa.FaceControl.FaceMessageBox("", text, MessageBoxButtons.OK).ShowDialog();
return;
}
string[] arr = new string[info.Count];
PointF[] lst = new PointF[info.Count];
for (int i = 0; i < info.Count; i++)
{
arr[i] = string.Format("({0}) ", i + 1) + info[i].Text.Replace("\r\n", "");
lst[i] = info[i].Center;
}
LstCode.Items.AddRange(arr);
PicShow.AddCodeCenter(lst);
}
private void BtnSaveImage_Click(object sender, EventArgs e)
{
SaveFileDialog dlg = new() { Filter = "JPEG图片|*.jpg|BMP图片|*.bmp|PNG图片|*.png" };
if (dlg.ShowDialog() != DialogResult.OK) return;
switch (dlg.FilterIndex)
{
case 0: bmp.Save(dlg.FileName, System.Drawing.Imaging.ImageFormat.Jpeg); break;
case 1: bmp.Save(dlg.FileName, System.Drawing.Imaging.ImageFormat.Bmp); break;
case 2: bmp.Save(dlg.FileName, System.Drawing.Imaging.ImageFormat.Png); break;
}
string text = Asa.FaceControl.Language.Dialog(LanguageDialogKey.SAVE_SUCCEED);
new Asa.FaceControl.FaceMessageBox("", text, MessageBoxButtons.OK).ShowDialog();
}
}
}