Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
孙克
/
GeneralClassLibrary
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 7ce5a30d
由
LN
编写于
2020-03-11 18:12:28 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
相机获取图片修改
1 个父辈
ca0df4ec
隐藏空白字符变更
内嵌
并排
正在显示
12 个修改的文件
包含
1303 行增加
和
127 行删除
CodeLibraryProject/CodeLibrary/CodeLibrary.csproj
CodeLibraryProject/CodeLibrary/FrmCodeDecode.Designer.cs
CodeLibraryProject/CodeLibrary/FrmCodeDecode.cs
CodeLibraryProject/CodeLibrary/FrmCodeLearn.cs
CodeLibraryProject/CodeLibrary/HDCodeHelper.cs
CodeLibraryProject/CodeLibrary/HDLogUtil.cs
CodeLibraryProject/CodeLibrary/camera/Basler.cs
CodeLibraryProject/CodeLibrary/camera/Common.cs
CodeLibraryProject/CodeLibrary/camera/HIK.cs
CodeLibraryProject/CodeTest/CodeCreater.cs
CodeLibraryProject/CodeTest/Program.cs
dll/CodeLibrary.dll
CodeLibraryProject/CodeLibrary/CodeLibrary.csproj
查看文件 @
7ce5a30
...
...
@@ -57,14 +57,15 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="camera\Basler.cs" />
<Compile Include="camera\Common.cs" />
<Compile Include="camera\HIK.cs" />
<Compile Include="FrmBase.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="FrmBase.Designer.cs">
<DependentUpon>FrmBase.cs</DependentUpon>
</Compile>
<Compile Include="HIKCamera.cs" />
<Compile Include="BaslerCamera.cs" />
<Compile Include="FrmCodeLearn.cs">
<SubType>Form</SubType>
</Compile>
...
...
CodeLibraryProject/CodeLibrary/FrmCodeDecode.Designer.cs
查看文件 @
7ce5a30
...
...
@@ -55,13 +55,14 @@
this
.
label4
=
new
System
.
Windows
.
Forms
.
Label
();
this
.
btnLight
=
new
System
.
Windows
.
Forms
.
Button
();
this
.
button1
=
new
System
.
Windows
.
Forms
.
Button
();
this
.
btnScanTest
=
new
System
.
Windows
.
Forms
.
Button
();
((
System
.
ComponentModel
.
ISupportInitialize
)(
this
.
pictureBox1
)).
BeginInit
();
this
.
SuspendLayout
();
//
// txtPath
//
this
.
txtPath
.
Anchor
=
((
System
.
Windows
.
Forms
.
AnchorStyles
)((
System
.
Windows
.
Forms
.
AnchorStyles
.
Top
|
System
.
Windows
.
Forms
.
AnchorStyles
.
Right
)));
this
.
txtPath
.
Location
=
new
System
.
Drawing
.
Point
(
864
,
92
);
this
.
txtPath
.
Location
=
new
System
.
Drawing
.
Point
(
1047
,
92
);
this
.
txtPath
.
Name
=
"txtPath"
;
this
.
txtPath
.
Size
=
new
System
.
Drawing
.
Size
(
321
,
21
);
this
.
txtPath
.
TabIndex
=
0
;
...
...
@@ -82,7 +83,7 @@
this
.
pictureBox1
.
Anchor
=
((
System
.
Windows
.
Forms
.
AnchorStyles
)(((
System
.
Windows
.
Forms
.
AnchorStyles
.
Top
|
System
.
Windows
.
Forms
.
AnchorStyles
.
Bottom
)
|
System
.
Windows
.
Forms
.
AnchorStyles
.
Right
)));
this
.
pictureBox1
.
BackColor
=
System
.
Drawing
.
Color
.
White
;
this
.
pictureBox1
.
Location
=
new
System
.
Drawing
.
Point
(
734
,
115
);
this
.
pictureBox1
.
Location
=
new
System
.
Drawing
.
Point
(
917
,
115
);
this
.
pictureBox1
.
Name
=
"pictureBox1"
;
this
.
pictureBox1
.
Size
=
new
System
.
Drawing
.
Size
(
451
,
313
);
this
.
pictureBox1
.
SizeMode
=
System
.
Windows
.
Forms
.
PictureBoxSizeMode
.
Zoom
;
...
...
@@ -92,7 +93,7 @@
// txtResult
//
this
.
txtResult
.
Anchor
=
((
System
.
Windows
.
Forms
.
AnchorStyles
)((
System
.
Windows
.
Forms
.
AnchorStyles
.
Bottom
|
System
.
Windows
.
Forms
.
AnchorStyles
.
Right
)));
this
.
txtResult
.
Location
=
new
System
.
Drawing
.
Point
(
734
,
431
);
this
.
txtResult
.
Location
=
new
System
.
Drawing
.
Point
(
917
,
431
);
this
.
txtResult
.
Multiline
=
true
;
this
.
txtResult
.
Name
=
"txtResult"
;
this
.
txtResult
.
Size
=
new
System
.
Drawing
.
Size
(
450
,
290
);
...
...
@@ -132,9 +133,9 @@
this
.
hWindowControl1
.
ImagePart
=
new
System
.
Drawing
.
Rectangle
(
0
,
0
,
640
,
480
);
this
.
hWindowControl1
.
Location
=
new
System
.
Drawing
.
Point
(
11
,
115
);
this
.
hWindowControl1
.
Name
=
"hWindowControl1"
;
this
.
hWindowControl1
.
Size
=
new
System
.
Drawing
.
Size
(
717
,
606
);
this
.
hWindowControl1
.
Size
=
new
System
.
Drawing
.
Size
(
900
,
606
);
this
.
hWindowControl1
.
TabIndex
=
8
;
this
.
hWindowControl1
.
WindowSize
=
new
System
.
Drawing
.
Size
(
717
,
606
);
this
.
hWindowControl1
.
WindowSize
=
new
System
.
Drawing
.
Size
(
900
,
606
);
//
// btnbarCode
//
...
...
@@ -151,7 +152,7 @@
//
this
.
btnLearn
.
Anchor
=
((
System
.
Windows
.
Forms
.
AnchorStyles
)((
System
.
Windows
.
Forms
.
AnchorStyles
.
Top
|
System
.
Windows
.
Forms
.
AnchorStyles
.
Right
)));
this
.
btnLearn
.
Font
=
new
System
.
Drawing
.
Font
(
"微软雅黑"
,
9F
,
System
.
Drawing
.
FontStyle
.
Regular
,
System
.
Drawing
.
GraphicsUnit
.
Point
,
((
byte
)(
134
)));
this
.
btnLearn
.
Location
=
new
System
.
Drawing
.
Point
(
1
066
,
12
);
this
.
btnLearn
.
Location
=
new
System
.
Drawing
.
Point
(
1
249
,
12
);
this
.
btnLearn
.
Name
=
"btnLearn"
;
this
.
btnLearn
.
Size
=
new
System
.
Drawing
.
Size
(
109
,
33
);
this
.
btnLearn
.
TabIndex
=
10
;
...
...
@@ -238,7 +239,7 @@
//
this
.
btnExit
.
Anchor
=
((
System
.
Windows
.
Forms
.
AnchorStyles
)((
System
.
Windows
.
Forms
.
AnchorStyles
.
Top
|
System
.
Windows
.
Forms
.
AnchorStyles
.
Right
)));
this
.
btnExit
.
Font
=
new
System
.
Drawing
.
Font
(
"微软雅黑"
,
9F
,
System
.
Drawing
.
FontStyle
.
Regular
,
System
.
Drawing
.
GraphicsUnit
.
Point
,
((
byte
)(
134
)));
this
.
btnExit
.
Location
=
new
System
.
Drawing
.
Point
(
1
066
,
50
);
this
.
btnExit
.
Location
=
new
System
.
Drawing
.
Point
(
1
249
,
50
);
this
.
btnExit
.
Name
=
"btnExit"
;
this
.
btnExit
.
Size
=
new
System
.
Drawing
.
Size
(
109
,
33
);
this
.
btnExit
.
TabIndex
=
18
;
...
...
@@ -250,7 +251,7 @@
//
this
.
label1
.
Anchor
=
((
System
.
Windows
.
Forms
.
AnchorStyles
)((
System
.
Windows
.
Forms
.
AnchorStyles
.
Top
|
System
.
Windows
.
Forms
.
AnchorStyles
.
Right
)));
this
.
label1
.
Font
=
new
System
.
Drawing
.
Font
(
"微软雅黑"
,
9F
,
System
.
Drawing
.
FontStyle
.
Regular
,
System
.
Drawing
.
GraphicsUnit
.
Point
,
((
byte
)(
134
)));
this
.
label1
.
Location
=
new
System
.
Drawing
.
Point
(
731
,
95
);
this
.
label1
.
Location
=
new
System
.
Drawing
.
Point
(
914
,
95
);
this
.
label1
.
Name
=
"label1"
;
this
.
label1
.
Size
=
new
System
.
Drawing
.
Size
(
127
,
17
);
this
.
label1
.
TabIndex
=
19
;
...
...
@@ -330,7 +331,7 @@
this
.
txtParamPath
.
Enabled
=
false
;
this
.
txtParamPath
.
Location
=
new
System
.
Drawing
.
Point
(
205
,
92
);
this
.
txtParamPath
.
Name
=
"txtParamPath"
;
this
.
txtParamPath
.
Size
=
new
System
.
Drawing
.
Size
(
523
,
21
);
this
.
txtParamPath
.
Size
=
new
System
.
Drawing
.
Size
(
706
,
21
);
this
.
txtParamPath
.
TabIndex
=
28
;
//
// label4
...
...
@@ -367,11 +368,23 @@
this
.
button1
.
Visible
=
false
;
this
.
button1
.
Click
+=
new
System
.
EventHandler
(
this
.
button1_Click
);
//
// btnScanTest
//
this
.
btnScanTest
.
Font
=
new
System
.
Drawing
.
Font
(
"微软雅黑"
,
9F
,
System
.
Drawing
.
FontStyle
.
Regular
,
System
.
Drawing
.
GraphicsUnit
.
Point
,
((
byte
)(
134
)));
this
.
btnScanTest
.
Location
=
new
System
.
Drawing
.
Point
(
1069
,
12
);
this
.
btnScanTest
.
Name
=
"btnScanTest"
;
this
.
btnScanTest
.
Size
=
new
System
.
Drawing
.
Size
(
167
,
33
);
this
.
btnScanTest
.
TabIndex
=
30
;
this
.
btnScanTest
.
Text
=
"扫码测试"
;
this
.
btnScanTest
.
UseVisualStyleBackColor
=
true
;
this
.
btnScanTest
.
Click
+=
new
System
.
EventHandler
(
this
.
btnScanTest_Click
);
//
// FrmCodeDecode
//
this
.
AutoScaleDimensions
=
new
System
.
Drawing
.
SizeF
(
6F
,
12F
);
this
.
AutoScaleMode
=
System
.
Windows
.
Forms
.
AutoScaleMode
.
Font
;
this
.
ClientSize
=
new
System
.
Drawing
.
Size
(
1192
,
729
);
this
.
ClientSize
=
new
System
.
Drawing
.
Size
(
1375
,
729
);
this
.
Controls
.
Add
(
this
.
btnScanTest
);
this
.
Controls
.
Add
(
this
.
button1
);
this
.
Controls
.
Add
(
this
.
txtParamPath
);
this
.
Controls
.
Add
(
this
.
label4
);
...
...
@@ -403,6 +416,7 @@
this
.
Name
=
"FrmCodeDecode"
;
this
.
Text
=
"二维码识别"
;
this
.
WindowState
=
System
.
Windows
.
Forms
.
FormWindowState
.
Maximized
;
this
.
FormClosing
+=
new
System
.
Windows
.
Forms
.
FormClosingEventHandler
(
this
.
FrmCodeDecode_FormClosing
);
this
.
Load
+=
new
System
.
EventHandler
(
this
.
FrmMain_Load
);
((
System
.
ComponentModel
.
ISupportInitialize
)(
this
.
pictureBox1
)).
EndInit
();
this
.
ResumeLayout
(
false
);
...
...
@@ -438,6 +452,7 @@
private
System
.
Windows
.
Forms
.
Label
label4
;
private
System
.
Windows
.
Forms
.
Button
btnLight
;
private
System
.
Windows
.
Forms
.
Button
button1
;
private
System
.
Windows
.
Forms
.
Button
btnScanTest
;
}
}
CodeLibraryProject/CodeLibrary/FrmCodeDecode.cs
查看文件 @
7ce5a30
...
...
@@ -18,11 +18,11 @@ using System.IO;
namespace
CodeLibrary
{
public
partial
class
FrmCodeDecode
:
FrmBase
{
{
private
Stopwatch
stopwatch
=
new
Stopwatch
();
private
List
<
string
>
baslerNameList
=
new
List
<
string
>();
private
List
<
string
>
hikNameList
=
new
List
<
string
>();
//
private List<string> baslerNameList = new List<string>();
//
private List<string> hikNameList = new List<string>();
public
FrmCodeDecode
()
{
InitializeComponent
();
...
...
@@ -35,7 +35,7 @@ namespace CodeLibrary
private
void
FrmMain_Load
(
object
sender
,
EventArgs
e
)
{
Control
.
CheckForIllegalCrossThreadCalls
=
false
;
cmbCount
.
Items
.
Clear
();
cmbCount
.
Items
.
Clear
();
cmbCount
.
Items
.
Add
(-
1
);
for
(
int
i
=
1
;
i
<=
300
;
i
++)
{
cmbCount
.
Items
.
Add
(
i
);
...
...
@@ -53,25 +53,27 @@ namespace CodeLibrary
{
cmbCodeType
.
Items
.
Add
(
"QR Code"
);
cmbCodeType
.
SelectedIndex
=
0
;
}
}
}
private
void
LoadCamera
()
{
string
[]
camerName
=
BaslerCamera
.
Instance
.
CameraName
;
baslerNameList
.
AddRange
(
camerName
);
//
string[] camerName = BaslerCamera.Instance.CameraName;
//
baslerNameList.AddRange(camerName);
cmbCamera
.
Items
.
Clear
();
foreach
(
string
str
in
camerName
)
Camera
.
Type
=
CameraType
.
HIK
;
Camera
.
_cam
.
Load
();
foreach
(
string
str
in
Camera
.
_cam
.
Name
)
{
cmbCamera
.
Items
.
Add
(
str
);
}
camerName
=
HIKCamera
.
Instance
.
CameraName
;
hikNameList
.
AddRange
(
camerName
);
foreach
(
string
str
in
camerName
)
{
cmbCamera
.
Items
.
Add
(
str
);
}
if
(
c
amerName
.
Length
>
0
)
//
camerName = HIKCamera.Instance.CameraName;
//
hikNameList.AddRange(camerName);
//
foreach (string str in camerName)
//
{
//
cmbCamera.Items.Add(str);
//
}
if
(
c
mbCamera
.
Items
.
Count
>
0
)
{
cmbCamera
.
SelectedIndex
=
0
;
}
...
...
@@ -98,12 +100,12 @@ namespace CodeLibrary
Image
img
=
(
Image
)
Image
.
FromFile
(
filename
).
Clone
();
pictureBox1
.
Image
=
img
;
}
private
void
btnErZhi_Click
(
object
sender
,
EventArgs
e
)
{
if
(
pictureBox1
.
Image
==
null
||
txtPath
.
Text
.
Equals
(
""
))
{
MessageBox
.
Show
(
selImage
,
title
,
MessageBoxButtons
.
OK
,
MessageBoxIcon
.
Error
);
MessageBox
.
Show
(
selImage
,
title
,
MessageBoxButtons
.
OK
,
MessageBoxIcon
.
Error
);
return
;
}
Bitmap
map
=
new
Bitmap
(
pictureBox1
.
Image
);
...
...
@@ -114,15 +116,15 @@ namespace CodeLibrary
{
if
(
pictureBox1
.
Image
==
null
||
txtPath
.
Text
.
Equals
(
""
))
{
MessageBox
.
Show
(
selImage
,
title
,
MessageBoxButtons
.
OK
,
MessageBoxIcon
.
Error
);
MessageBox
.
Show
(
selImage
,
title
,
MessageBoxButtons
.
OK
,
MessageBoxIcon
.
Error
);
return
;
}
Bitmap
map
=
new
Bitmap
(
pictureBox1
.
Image
);
Bitmap
newMap
=
ImageHelper
.
ToGray
(
map
);
pictureBox1
.
Image
=
newMap
;
}
private
void
ShowCode
(
List
<
CodeInfo
>
list
)
{
if
(
list
.
Count
>
0
)
...
...
@@ -130,7 +132,7 @@ namespace CodeLibrary
txtResult
.
Text
+=
"\r\n code list:"
;
foreach
(
CodeInfo
code
in
list
)
{
txtResult
.
Text
+=
"\r\n"
+
""
+
code
.
CodeType
+
" (X:"
+
code
.
X
+
",Y:"
+
code
.
Y
+
") "
+
code
.
CodeStr
;
txtResult
.
Text
+=
"\r\n"
+
""
+
code
.
CodeType
+
" (X:"
+
code
.
X
+
",Y:"
+
code
.
Y
+
") "
+
code
.
CodeStr
;
}
}
else
...
...
@@ -140,13 +142,13 @@ namespace CodeLibrary
}
private
void
btnbarCode_Click
(
object
sender
,
EventArgs
e
)
{
if
(
pictureBox1
.
Image
==
null
)
{
if
(
pictureBox1
.
Image
==
null
)
{
MessageBox
.
Show
(
selImage
,
title
,
MessageBoxButtons
.
OK
,
MessageBoxIcon
.
Error
);
MessageBox
.
Show
(
selImage
,
title
,
MessageBoxButtons
.
OK
,
MessageBoxIcon
.
Error
);
return
;
}
int
count
=
cmbCount
.
SelectedIndex
;
int
count
=
cmbCount
.
SelectedIndex
;
txtResult
.
Text
=
""
;
stopwatch
.
Restart
();
HDCodeHelper
.
HalconWindow
=
this
.
hWindowControl1
.
HalconWindow
;
...
...
@@ -176,10 +178,10 @@ namespace CodeLibrary
{
if
(
pictureBox1
.
Image
==
null
)
{
MessageBox
.
Show
(
selImage
,
title
,
MessageBoxButtons
.
OK
,
MessageBoxIcon
.
Error
);
MessageBox
.
Show
(
selImage
,
title
,
MessageBoxButtons
.
OK
,
MessageBoxIcon
.
Error
);
return
;
}
int
count
=
cmbCount
.
SelectedIndex
;
int
count
=
cmbCount
.
SelectedIndex
;
txtResult
.
Text
=
""
;
stopwatch
.
Restart
();
...
...
@@ -217,29 +219,44 @@ namespace CodeLibrary
}
private
Bitmap
GetCameraBitmap
()
{
int
index
=
cmbCamera
.
SelectedIndex
;
string
camerName
=
cmbCamera
.
Text
;
if
(
index
<
0
)
try
{
MessageBox
.
Show
(
selCamera
);
return
null
;
}
if
(
baslerNameList
.
Contains
(
camerName
))
{
BaslerCamera
.
Instance
.
Open
(
camerName
);
BaslerCamera
.
Instance
.
GrabOne
();
Bitmap
bitmap
=
BaslerCamera
.
Instance
.
Image
;
BaslerCamera
.
Instance
.
Close
();
return
bitmap
;
int
index
=
cmbCamera
.
SelectedIndex
;
string
camerName
=
cmbCamera
.
Text
;
if
(
index
<
0
)
{
MessageBox
.
Show
(
selCamera
);
return
null
;
}
//if (baslerNameList.Contains(camerName))
//{
// BaslerCamera.Instance.Open(camerName);
// BaslerCamera.Instance.GrabOne();
// Bitmap bitmap = BaslerCamera.Instance.Image;
// BaslerCamera.Instance.Close();
// return bitmap;
//}
//else
//{
// HIKCamera.Instance.Open(camerName);
// HIKCamera.Instance.GrabOne();
// Bitmap bitmap = HIKCamera.Instance.Image;
// HIKCamera.Instance.Close();
// return bitmap;
//}
Bitmap
map
=
Camera
.
_cam
.
GrabOneImage
(
camerName
);
if
(
map
==
null
)
{
Camera
.
_cam
.
Close
(
camerName
);
map
=
Camera
.
_cam
.
GrabOneImage
(
camerName
);
}
return
map
;
}
else
catch
(
Exception
ex
)
{
HIKCamera
.
Instance
.
Open
(
camerName
);
HIKCamera
.
Instance
.
GrabOne
();
Bitmap
bitmap
=
HIKCamera
.
Instance
.
Image
;
HIKCamera
.
Instance
.
Close
();
return
bitmap
;
MessageBox
.
Show
(
ex
.
ToString
());
}
return
null
;
}
private
void
btnCameraImage_Click
(
object
sender
,
EventArgs
e
)
{
...
...
@@ -251,7 +268,6 @@ namespace CodeLibrary
HObject
hoImage
=
HDCodeHelper
.
Bitmap2HObjectBpp24
(
bitmap
);
HDCodeLearnHelper
.
DefaultImage
=
hoImage
;
}
}
private
void
btnExit_Click
(
object
sender
,
EventArgs
e
)
...
...
@@ -263,11 +279,11 @@ namespace CodeLibrary
{
if
(
pictureBox1
.
Image
==
null
||
txtPath
.
Text
.
Equals
(
""
))
{
MessageBox
.
Show
(
selImage
,
title
,
MessageBoxButtons
.
OK
,
MessageBoxIcon
.
Error
);
MessageBox
.
Show
(
selImage
,
title
,
MessageBoxButtons
.
OK
,
MessageBoxIcon
.
Error
);
return
;
}
Bitmap
map
=
new
Bitmap
(
pictureBox1
.
Image
);
Bitmap
newMap
=
ImageHelper
.
KiLighten
(
map
,
10
);
Bitmap
newMap
=
ImageHelper
.
KiLighten
(
map
,
10
);
pictureBox1
.
Image
=
newMap
;
}
...
...
@@ -275,13 +291,13 @@ namespace CodeLibrary
{
if
(
pictureBox1
.
Image
==
null
||
txtPath
.
Text
.
Equals
(
""
))
{
MessageBox
.
Show
(
selImage
,
title
,
MessageBoxButtons
.
OK
,
MessageBoxIcon
.
Error
);
MessageBox
.
Show
(
selImage
,
title
,
MessageBoxButtons
.
OK
,
MessageBoxIcon
.
Error
);
return
;
}
Bitmap
map
=
new
Bitmap
(
pictureBox1
.
Image
);
Bitmap
newMap
=
ImageHelper
.
KiLighten
(
map
,
-
10
);
pictureBox1
.
Image
=
newMap
;
}
}
private
void
cmbCodeType_SelectedIndexChanged
(
object
sender
,
EventArgs
e
)
{
...
...
@@ -312,46 +328,138 @@ namespace CodeLibrary
private
void
TestTimer_Elapsed
(
object
sender
,
System
.
Timers
.
ElapsedEventArgs
e
)
{
try
{
if
(
pictureBox1
.
Image
==
null
)
try
{
return
;
}
int
count
=
cmbCount
.
SelectedIndex
;
txtResult
.
Text
=
""
;
stopwatch
.
Restart
();
if
(
pictureBox1
.
Image
==
null
)
{
return
;
}
int
count
=
cmbCount
.
SelectedIndex
;
txtResult
.
Text
=
""
;
stopwatch
.
Restart
();
testCount
++;
Bitmap
map
=
new
Bitmap
(
pictureBox1
.
Image
);
HObject
ho_image
=
HDCodeHelper
.
Bitmap2HObjectBpp24
(
map
);
Bitmap
map
=
new
Bitmap
(
pictureBox1
.
Image
);
HObject
ho_image
=
HDCodeHelper
.
Bitmap2HObjectBpp24
(
map
);
txtResult
.
Text
+=
"\r\n elapsed time:"
+
stopwatch
.
Elapsed
.
ToString
();
hWindowControl1
.
HalconWindow
.
SetPart
(
0
,
0
,
map
.
Height
,
map
.
Width
);
HOperatorSet
.
DispObj
(
ho_image
,
hWindowControl1
.
HalconWindow
);
ShowImage
(
ho_image
);
HDCodeHelper
.
HalconWindow
=
this
.
hWindowControl1
.
HalconWindow
;
string
codeParamPath
=
HDCodeHelper
.
GetCodeParamFilePath
(
cmbCodeType
.
Text
);
if
(
chbUseParam
.
Checked
.
Equals
(
false
))
{
codeParamPath
=
""
;
}
List
<
CodeInfo
>
codeList
=
new
List
<
CodeInfo
>();
if
(
cmbCodeType
.
Text
.
ToLower
().
Equals
(
"barcode"
))
{
codeList
=
HDCodeHelper
.
DecodeBarCode
(
ho_image
);
txtResult
.
Text
+=
"\r\n elapsed time:"
+
stopwatch
.
Elapsed
.
ToString
();
hWindowControl1
.
HalconWindow
.
SetPart
(
0
,
0
,
map
.
Height
,
map
.
Width
);
HOperatorSet
.
DispObj
(
ho_image
,
hWindowControl1
.
HalconWindow
);
ShowImage
(
ho_image
);
HDCodeHelper
.
HalconWindow
=
this
.
hWindowControl1
.
HalconWindow
;
string
codeParamPath
=
HDCodeHelper
.
GetCodeParamFilePath
(
cmbCodeType
.
Text
);
if
(
chbUseParam
.
Checked
.
Equals
(
false
))
{
codeParamPath
=
""
;
}
List
<
CodeInfo
>
codeList
=
new
List
<
CodeInfo
>();
if
(
cmbCodeType
.
Text
.
ToLower
().
Equals
(
"barcode"
))
{
codeList
=
HDCodeHelper
.
DecodeBarCode
(
ho_image
);
}
else
{
codeList
=
HDCodeHelper
.
DecodeCode
(
ho_image
,
count
,
codeParamPath
,
cmbCodeType
.
Text
);
}
ShowCode
(
codeList
);
txtResult
.
Text
+=
"\r\n elapsed time:"
+
stopwatch
.
Elapsed
.
ToString
();
HDLogUtil
.
info
(
"第【"
+
testCount
+
"】次扫码测试结束"
);
}
else
catch
(
Exception
ex
)
{
codeList
=
HDCodeHelper
.
DecodeCode
(
ho_image
,
count
,
codeParamPath
,
cmbCodeType
.
Text
);
HDLogUtil
.
error
(
ex
.
ToString
()
);
}
ShowCode
(
codeList
);
}
txtResult
.
Text
+=
"\r\n elapsed time:"
+
stopwatch
.
Elapsed
.
ToString
();
HDLogUtil
.
info
(
"第【"
+
testCount
+
"】次扫码测试结束"
);
}
catch
(
Exception
ex
)
private
void
FrmCodeDecode_FormClosing
(
object
sender
,
FormClosingEventArgs
e
)
{
Camera
.
_cam
.
CloseAll
();
}
//private void btnScanTest_Click(object sender, EventArgs e)
//{
// Image img = (Image)Image.FromFile(@"E:\GigE-MV-CE200-10GC (00E06252332)\16-05-15-984.bmp").Clone();
// using (Bitmap bitmap = new Bitmap(img))
// //using (Bitmap bitmap = GetCameraBitmap())
// {
// if (bitmap != null)
// {
// System.Threading.Thread.Sleep(1);
// //转换托盘大概100-150ms,不打印日志
// HalconDotNet.HObject ho_Image = HDCodeHelper.Bitmap2HObjectBpp24(bitmap);
// // LogUtil.info(" 相机【" + cameraName + "】转换图片完成,开始扫码");
// List<CodeInfo> cc = new List<CodeInfo>();
// string str = "";
// List<string> codeTypeList = new List<string>(HDCodeLearnHelper.codeTypeList);
// string r = "";
// int count = cmbCount.SelectedIndex;
// foreach (string codeType in codeTypeList)
// {
// //判断是否是一维码
// if (codeType.ToLower().Equals("barcode"))
// {
// cc = HDCodeHelper.DecodeBarCode(ho_Image);
// }
// else
// {
// string codeParamPath = HDCodeHelper.GetCodeParamFilePath(codeType);
// cc = HDCodeHelper.DecodeCode(ho_Image, count, codeParamPath, codeType);
// }
// foreach (CodeInfo c in cc)
// {
// r += (c.CodeStr) + "##";
// }
// }
// MessageBox.Show(r);
// // ShowCode(cc);
// ho_Image.Dispose();
// bitmap.Dispose();
// }
// }
//}
private
void
btnScanTest_Click
(
object
sender
,
EventArgs
e
)
{
using
(
Bitmap
bitmap
=
GetCameraBitmap
())
{
HDLogUtil
.
error
(
ex
.
ToString
());
if
(
bitmap
!=
null
)
{
HDLogUtil
.
info
(
"获取图片完成,开始转换图片,并扫码"
);
System
.
Threading
.
Thread
.
Sleep
(
1
);
//转换托盘大概100-150ms,不打印日志
Bitmap
bit
=
new
Bitmap
(
bitmap
);
HalconDotNet
.
HObject
ho_Image
=
HDCodeHelper
.
Bitmap2HObjectBpp24
(
bit
);
// LogUtil.info(" 相机【" + cameraName + "】转换图片完成,开始扫码");
List
<
CodeInfo
>
cc
=
new
List
<
CodeInfo
>();
string
str
=
""
;
List
<
string
>
codeTypeList
=
new
List
<
string
>(
HDCodeLearnHelper
.
codeTypeList
);
string
r
=
""
;
int
count
=
cmbCount
.
SelectedIndex
;
foreach
(
string
codeType
in
codeTypeList
)
{
//判断是否是一维码
if
(
codeType
.
ToLower
().
Equals
(
"barcode"
))
{
cc
=
HDCodeHelper
.
DecodeBarCode
(
ho_Image
);
}
else
{
string
codeParamPath
=
HDCodeHelper
.
GetCodeParamFilePath
(
codeType
);
cc
=
HDCodeHelper
.
DecodeCode
(
ho_Image
,
count
,
codeParamPath
,
codeType
);
}
foreach
(
CodeInfo
c
in
cc
)
{
r
+=
(
c
.
CodeStr
)
+
"##"
;
}
}
MessageBox
.
Show
(
r
);
// ShowCode(cc);
ho_Image
.
Dispose
();
bitmap
.
Dispose
();
}
}
}
}
...
...
CodeLibraryProject/CodeLibrary/FrmCodeLearn.cs
查看文件 @
7ce5a30
...
...
@@ -37,20 +37,21 @@ namespace CodeLibrary
MessageBox
.
Show
(
selCamera
);
return
null
;
}
if
(
baslerNameList
.
Contains
(
camerName
))
{
BaslerCamera
.
Instance
.
Open
(
camerName
);
BaslerCamera
.
Instance
.
GrabOne
();
bitmap
=
BaslerCamera
.
Instance
.
Image
;
BaslerCamera
.
Instance
.
Close
();
}
else
{
HIKCamera
.
Instance
.
Open
(
camerName
);
HIKCamera
.
Instance
.
GrabOne
();
bitmap
=
HIKCamera
.
Instance
.
Image
;
HIKCamera
.
Instance
.
Close
();
}
//if (baslerNameList.Contains(camerName))
//{
// BaslerCamera.Instance.Open(camerName);
// BaslerCamera.Instance.GrabOne();
// bitmap = BaslerCamera.Instance.Image;
// BaslerCamera.Instance.Close();
//}
//else
//{
// HIKCamera.Instance.Open(camerName);
// HIKCamera.Instance.GrabOne();
// bitmap = HIKCamera.Instance.Image;
// HIKCamera.Instance.Close();
//}
bitmap
=
Camera
.
_cam
.
GrabOneImage
(
camerName
);
return
bitmap
;
}
private
void
btnOpen_Click
(
object
sender
,
EventArgs
e
)
...
...
@@ -106,21 +107,21 @@ namespace CodeLibrary
}
private
void
LoadCamera
()
{
string
[]
camerName
=
BaslerCamera
.
Instance
.
CameraName
;
baslerNameList
.
AddRange
(
camerName
);
//
string[] camerName = BaslerCamera.Instance.CameraName;
//
baslerNameList.AddRange(camerName);
cmbCamera
.
Items
.
Clear
();
foreach
(
string
str
in
camer
Name
)
foreach
(
string
str
in
Camera
.
_cam
.
Name
)
{
cmbCamera
.
Items
.
Add
(
str
);
}
camerName
=
HIKCamera
.
Instance
.
CameraName
;
hikNameList
.
AddRange
(
camerName
);
foreach
(
string
str
in
camerName
)
{
cmbCamera
.
Items
.
Add
(
str
);
}
if
(
c
amerName
.
Length
>
0
)
//
camerName = HIKCamera.Instance.CameraName;
//
hikNameList.AddRange(camerName);
//
foreach (string str in camerName)
//
{
//
cmbCamera.Items.Add(str);
//
}
if
(
c
mbCamera
.
Items
.
Count
>
0
)
{
cmbCamera
.
SelectedIndex
=
0
;
}
...
...
CodeLibraryProject/CodeLibrary/HDCodeHelper.cs
查看文件 @
7ce5a30
...
...
@@ -80,6 +80,7 @@ namespace CodeLibrary
}
public
static
List
<
CodeInfo
>
DecodeCode
(
HObject
ho_Image
,
string
symbolType
,
string
hv_model_path
,
int
codeCount
)
{
HDLogUtil
.
info
(
" DecodeCode["
+
symbolType
+
"]["
+
hv_model_path
+
"]["
+
codeCount
+
"] 开始"
);
List
<
CodeInfo
>
codeList
=
new
List
<
CodeInfo
>();
try
{
...
...
@@ -137,12 +138,14 @@ namespace CodeLibrary
HDLogUtil
.
error
(
"处理二维码出错:索引="
+
i
+
","
+
resultList
.
ToString
());
}
}
}
}
HDLogUtil
.
info
(
" DecodeCode["
+
symbolType
+
"]["
+
hv_model_path
+
"]["
+
codeCount
+
"] 结束,返回数量:"
+
codeList
.
Count
);
return
codeList
;
}
catch
(
Exception
ex
)
{
HDLogUtil
.
error
(
"DecodeCode出错:"
+
ex
.
ToString
());
HDLogUtil
.
info
(
" DecodeCode["
+
symbolType
+
"]["
+
hv_model_path
+
"]["
+
codeCount
+
"] 结束,返回数量:"
+
codeList
.
Count
);
return
codeList
;
}
...
...
@@ -195,7 +198,7 @@ namespace CodeLibrary
ho_Image
.
Dispose
();
Rectangle
rect
=
new
Rectangle
(
0
,
0
,
bmp
.
Width
,
bmp
.
Height
);
BitmapData
srcBmpData
=
bmp
.
LockBits
(
rect
,
ImageLockMode
.
ReadOnly
,
PixelFormat
.
Format32bppRgb
);
BitmapData
srcBmpData
=
bmp
.
LockBits
(
rect
,
ImageLockMode
.
ReadOnly
,
bmp
.
PixelFormat
);
HOperatorSet
.
GenImageInterleaved
(
out
ho_Image
,
srcBmpData
.
Scan0
,
"bgrx"
,
bmp
.
Width
,
bmp
.
Height
,
0
,
"byte"
,
0
,
0
,
0
,
0
,
-
1
,
0
);
bmp
.
UnlockBits
(
srcBmpData
);
...
...
CodeLibraryProject/CodeLibrary/HDLogUtil.cs
查看文件 @
7ce5a30
...
...
@@ -34,12 +34,12 @@ namespace CodeLibrary
public
static
void
info
(
string
msg
)
{
LOGGER
.
Info
(
LOGGER
.
Logger
.
Name
+
" - "
+
msg
);
LOGGER
.
Info
(
"HDLogUtil"
+
" - "
+
msg
);
AddToBox
(
msg
);
}
public
static
void
debug
(
string
msg
)
{
LOGGER
.
Debug
(
LOGGER
.
Logger
.
Name
+
" - "
+
msg
);
LOGGER
.
Debug
(
"HDLogUtil"
+
" - "
+
msg
);
if
(
debug_opened
)
{
AddToBox
(
msg
);
...
...
@@ -48,7 +48,7 @@ namespace CodeLibrary
public
static
void
error
(
string
errorMsg
)
{
LOGGER
.
Error
(
LOGGER
.
Logger
.
Name
+
" - "
+
errorMsg
);
LOGGER
.
Error
(
"HDLogUtil"
+
" - "
+
errorMsg
);
AddToBox
(
errorMsg
);
}
private
static
void
AddToBox
(
string
msg
)
...
...
CodeLibraryProject/CodeLibrary/camera/Basler.cs
0 → 100644
查看文件 @
7ce5a30
using
System
;
using
Basler.Pylon
;
using
System.Drawing
;
using
System.Drawing.Imaging
;
using
System.Collections.Generic
;
namespace
CodeLibrary
{
partial
class
Basler
:
ClsCamera
{
/// <summary>
/// 当前相机
/// </summary>
private
global
::
Basler
.
Pylon
.
Camera
[]
cameraCurr
;
/// <summary>
/// 所有相机列表
/// </summary>
private
List
<
ICameraInfo
>
cameraAll
;
///// <summary>
///// 所有相机的名称
///// </summary>
//private List<string> cameraName;
/// <summary>
/// 连续抓图事件
/// </summary>
public
event
Continuous
Continuous_Event
;
public
override
void
Close
(
string
name
)
{
int
index
=
Array
.
FindIndex
(
_name
,
s
=>
s
==
name
);
if
(
index
==
-
1
)
return
;
if
(
cameraCurr
[
index
]
!=
null
)
{
_isOpen
[
index
]
=
false
;
cameraCurr
[
index
].
Close
();
cameraCurr
[
index
].
Dispose
();
cameraCurr
[
index
]
=
null
;
}
}
public
override
void
Close
(
int
index
)
{
if
(
cameraCurr
[
index
]
!=
null
)
{
_isOpen
[
index
]
=
false
;
cameraCurr
[
index
].
Close
();
cameraCurr
[
index
].
Dispose
();
cameraCurr
[
index
]
=
null
;
}
}
public
override
void
CloseAll
()
{
for
(
int
i
=
0
;
i
<
cameraCurr
.
Length
;
i
++)
{
if
(
cameraCurr
[
i
]
!=
null
)
{
_isOpen
[
i
]
=
false
;
cameraCurr
[
i
].
Close
();
cameraCurr
[
i
].
Dispose
();
cameraCurr
[
i
]
=
null
;
}
}
}
//public override bool GrabContinuous(int index)
//{
// try
// {
// cameraCurr[index].Parameters[PLCamera.AcquisitionMode].SetValue(PLCamera.AcquisitionMode.Continuous);
// cameraCurr[index].StreamGrabber.Start(GrabStrategy.OneByOne, GrabLoop.ProvidedByStreamGrabber);
// _errInfo = "OK";
// return true;
// }
// catch (Exception ex)
// {
// _errInfo = ex.Message;
// return false;
// }
//}
//public override bool GrabOne()
//{
// try
// {
// cameraCurr[_index].Parameters[PLCamera.AcquisitionMode].SetValue(PLCamera.AcquisitionMode.SingleFrame);
// //cameraCur.StreamGrabber.Start();
// //IGrabResult grabResult = cameraCur.StreamGrabber.RetrieveResult(5000, TimeoutHandling.ThrowException);
// IGrabResult grabResult = cameraCurr[_index].StreamGrabber.GrabOne(5000);
// if (!grabResult.IsValid)
// {
// _errInfo = grabResult.ErrorDescription;
// return false;
// }
// _image = new Bitmap(grabResult.Width, grabResult.Height, PixelFormat.Format24bppRgb);
// BitmapData bmpData = _image.LockBits(new Rectangle(0, 0, grabResult.Width, grabResult.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
// IntPtr ptrBmp = bmpData.Scan0;
// int picSize = bmpData.Stride * grabResult.Height;
// PixelDataConverter conv = new PixelDataConverter();
// conv.OutputPixelFormat = PixelType.BGR8packed;
// conv.Convert(ptrBmp, picSize, grabResult);
// _buffer = new byte[picSize];
// System.Runtime.InteropServices.Marshal.Copy(ptrBmp, _buffer, 0, picSize);
// _image.UnlockBits(bmpData);
// _errInfo = "OK";
// return true;
// }
// catch (Exception ex)
// {
// _errInfo = ex.Message;
// return false;
// }
//}
public
override
bool
GrabOne
(
int
index
)
{
if
(
cameraCurr
[
index
]
!=
null
)
{
try
{
cameraCurr
[
index
].
Parameters
[
PLCamera
.
AcquisitionMode
].
SetValue
(
PLCamera
.
AcquisitionMode
.
SingleFrame
);
//cameraCur.StreamGrabber.Start();
//IGrabResult grabResult = cameraCur.StreamGrabber.RetrieveResult(5000, TimeoutHandling.ThrowException);
IGrabResult
grabResult
=
cameraCurr
[
index
].
StreamGrabber
.
GrabOne
(
5000
);
if
(!
grabResult
.
IsValid
)
{
_errInfo
=
grabResult
.
ErrorDescription
;
return
false
;
}
_image
=
new
Bitmap
(
grabResult
.
Width
,
grabResult
.
Height
,
PixelFormat
.
Format24bppRgb
);
BitmapData
bmpData
=
_image
.
LockBits
(
new
Rectangle
(
0
,
0
,
grabResult
.
Width
,
grabResult
.
Height
),
ImageLockMode
.
ReadWrite
,
PixelFormat
.
Format24bppRgb
);
IntPtr
ptrBmp
=
bmpData
.
Scan0
;
int
picSize
=
bmpData
.
Stride
*
grabResult
.
Height
;
PixelDataConverter
conv
=
new
PixelDataConverter
();
conv
.
OutputPixelFormat
=
PixelType
.
BGR8packed
;
conv
.
Convert
(
ptrBmp
,
picSize
,
grabResult
);
_buffer
=
new
byte
[
picSize
];
System
.
Runtime
.
InteropServices
.
Marshal
.
Copy
(
ptrBmp
,
_buffer
,
0
,
picSize
);
_image
.
UnlockBits
(
bmpData
);
_errInfo
=
"OK"
;
return
true
;
}
catch
(
Exception
ex
)
{
_errInfo
=
ex
.
Message
;
return
false
;
}
}
return
false
;
}
public
override
bool
GrabOne
(
string
name
)
{
int
idx
=
Array
.
FindIndex
(
_name
,
s
=>
s
==
name
);
if
(
idx
==
-
1
)
return
false
;
else
return
GrabOne
(
idx
);
}
public
override
void
GrabStop
(
int
index
)
{
if
(
cameraCurr
[
index
]
!=
null
)
cameraCurr
[
index
].
StreamGrabber
.
Stop
();
}
public
override
bool
Load
()
{
try
{
cameraAll
=
CameraFinder
.
Enumerate
();
cameraName
=
new
List
<
string
>();
foreach
(
ICameraInfo
info
in
cameraAll
)
cameraName
.
Add
(
info
[
CameraInfoKey
.
ModelName
].
ToString
()
+
" ("
+
info
[
CameraInfoKey
.
SerialNumber
].
ToString
()
+
")"
);
_name
=
cameraName
.
ToArray
();
_count
=
cameraName
.
Count
;
_isOpen
=
new
bool
[
_count
];
_width
=
new
int
[
_count
];
_height
=
new
int
[
_count
];
cameraCurr
=
new
global
::
Basler
.
Pylon
.
Camera
[
_count
];
_errInfo
=
"OK"
;
return
true
;
}
catch
(
Exception
ex
)
{
_errInfo
=
ex
.
Message
;
return
false
;
}
}
public
override
bool
Open
(
int
index
)
{
// _index = index;
if
(
index
<
0
||
index
>=
_count
)
{
_errInfo
=
"Not find"
;
return
false
;
}
if
(
cameraCurr
[
index
]
!=
null
)
Close
(
index
);
try
{
cameraCurr
[
index
]
=
new
global
::
Basler
.
Pylon
.
Camera
(
cameraAll
[
index
]);
//cameraCur.ConnectionLost += OnConnectionLost;
//cameraCur.CameraOpened += OnCameraOpened;
//cameraCur.CameraClosed += OnCameraClosed;
//cameraCur.StreamGrabber.GrabStarted += OnGrabStarted;
cameraCurr
[
index
].
StreamGrabber
.
ImageGrabbed
+=
OnImageGrabbed
;
//cameraCur.StreamGrabber.GrabStopped += OnGrabStopped;
cameraCurr
[
index
].
Open
();
_width
[
index
]
=
Convert
.
ToInt32
(
cameraCurr
[
index
].
Parameters
[
PLCamera
.
Width
].
GetValue
());
_height
[
index
]
=
Convert
.
ToInt32
(
cameraCurr
[
index
].
Parameters
[
PLCamera
.
Height
].
GetValue
());
cameraCurr
[
index
].
Parameters
[
PLCamera
.
UserSetSelector
].
SetValue
(
PLCamera
.
UserSetSelector
.
UserSet1
);
//加载用户设置1
bool
bln
=
cameraCurr
[
index
].
Parameters
[
PLCamera
.
UserSetLoad
].
TryExecute
();
//执行设置
_isOpen
[
index
]
=
true
;
_errInfo
=
"OK"
;
return
true
;
}
catch
(
Exception
ex
)
{
_errInfo
=
ex
.
Message
;
return
false
;
}
}
public
override
bool
Open
(
string
name
)
{
int
n
=
cameraName
.
FindIndex
(
s
=>
s
==
name
);
if
(
n
==
-
1
)
{
_errInfo
=
"Not find"
;
return
false
;
}
else
return
Open
(
n
);
}
public
override
bool
OpenAll
()
{
bool
rtn
=
true
;
for
(
int
i
=
0
;
i
<
cameraName
.
Count
;
i
++)
{
rtn
=
Open
(
i
);
if
(!
rtn
)
break
;
}
return
rtn
;
}
private
void
OnImageGrabbed
(
object
sender
,
ImageGrabbedEventArgs
e
)
{
try
{
IGrabResult
grabResult
=
e
.
GrabResult
;
if
(!
grabResult
.
IsValid
)
return
;
_image
=
new
Bitmap
(
grabResult
.
Width
,
grabResult
.
Height
,
PixelFormat
.
Format24bppRgb
);
BitmapData
bmpData
=
_image
.
LockBits
(
new
Rectangle
(
0
,
0
,
grabResult
.
Width
,
grabResult
.
Height
),
ImageLockMode
.
ReadWrite
,
PixelFormat
.
Format24bppRgb
);
IntPtr
ptrBmp
=
bmpData
.
Scan0
;
int
picSize
=
bmpData
.
Stride
*
grabResult
.
Height
;
PixelDataConverter
conv
=
new
PixelDataConverter
();
conv
.
OutputPixelFormat
=
PixelType
.
BGR8packed
;
conv
.
Convert
(
ptrBmp
,
picSize
,
grabResult
);
_buffer
=
new
byte
[
picSize
];
System
.
Runtime
.
InteropServices
.
Marshal
.
Copy
(
ptrBmp
,
Buffer
,
0
,
picSize
);
_image
.
UnlockBits
(
bmpData
);
Continuous_Event
?.
Invoke
();
}
catch
(
Exception
ex
)
{
_errInfo
=
ex
.
Message
;
}
finally
{
e
.
DisposeGrabResultIfClone
();
}
}
public
override
Bitmap
GrabOneImage
(
string
name
)
{
int
n
=
cameraName
.
FindIndex
(
s
=>
s
==
name
);
if
(
n
==
-
1
)
{
_errInfo
=
"Not find"
;
return
null
;
}
if
(
cameraCurr
[
n
]
!=
null
)
{
GrabOne
(
name
);
return
Image
;
}
return
null
;
}
}
}
\ No newline at end of file
CodeLibraryProject/CodeLibrary/camera/Common.cs
0 → 100644
查看文件 @
7ce5a30
using
System
;
using
System.Collections.Generic
;
using
System.Drawing
;
using
System.Linq
;
using
System.Text
;
namespace
CodeLibrary
{
/// <summary>
/// 相机
/// </summary>
public
class
Camera
:
ClsCamera
{
public
static
ClsCamera
_cam
;
private
static
CameraType
_type
;
/// <summary>
/// 连续采集事件
/// </summary>
public
static
event
Continuous
Continuous_Event
;
/// <summary>
/// 相机
/// </summary>
private
Camera
()
{
}
/// <summary>
/// 相机类型
/// </summary>
public
static
CameraType
Type
{
set
{
if
(
_cam
!=
null
)
{
return
;
// _cam.CloseAll();
}
_type
=
value
;
switch
(
_type
)
{
case
CameraType
.
HIK
:
_cam
=
new
HIK
();
((
HIK
)
_cam
).
Continuous_Event
+=
Camera_Continuous_Event
;
break
;
case
CameraType
.
Basler
:
_cam
=
new
Basler
();
((
Basler
)
_cam
).
Continuous_Event
+=
Camera_Continuous_Event
;
break
;
}
}
get
{
return
_type
;
}
}
/// <summary>
/// 错误信息
/// </summary>
public
override
string
ErrInfo
=>
_cam
.
ErrInfo
;
/// <summary>
/// 相机是否打开
/// </summary>
public
override
bool
[]
IsOpen
=>
_cam
.
IsOpen
;
/// <summary>
/// 相机总数
/// </summary>
public
override
int
Count
=>
_cam
.
Count
;
/// <summary>
/// 相机名称
/// </summary>
public
override
string
[]
Name
=>
_cam
.
Name
;
/// <summary>
/// 图像宽度
/// </summary>
public
override
int
[]
Width
=>
_cam
.
Width
;
/// <summary>
/// 图像高度
/// </summary>
public
override
int
[]
Height
=>
_cam
.
Height
;
/// <summary>
/// 图像缓存
/// </summary>
public
override
byte
[]
Buffer
=>
_cam
.
Buffer
;
/// <summary>
/// 图像
/// </summary>
public
override
Bitmap
Image
=>
_cam
.
Image
;
/// <summary>
/// 加载
/// </summary>
/// <returns></returns>
public
override
bool
Load
()
{
if
(
_cam
==
null
)
return
false
;
else
return
_cam
.
Load
();
}
/// <summary>
/// 打开相机
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
public
override
bool
Open
(
int
index
)
{
return
_cam
.
Open
(
index
);
}
/// <summary>
/// 打开相机
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public
override
bool
Open
(
string
name
)
{
return
_cam
.
Open
(
name
);
}
/// <summary>
/// 打开所有相机
/// </summary>
/// <returns></returns>
public
override
bool
OpenAll
()
{
return
_cam
.
OpenAll
();
}
///// <summary>
///// 连续抓取图像
///// </summary>
///// <returns></returns>
//public override bool GrabContinuous(int index)
//{
// return _cam.GrabContinuous( index);
//}
/// <summary>
/// 抓取一次图像
/// </summary>
/// <returns></returns>
public
override
bool
GrabOne
(
int
index
)
{
return
_cam
.
GrabOne
(
index
);
}
///// <summary>
///// 抓取一次图像
///// </summary>
///// <param name="index"></param>
///// <returns></returns>
//public override bool GrabOne(int index)
//{
// return _cam.GrabOne(index);
//}
/// <summary>
/// 抓取一次图像
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
public
override
bool
GrabOne
(
string
name
)
{
return
_cam
.
GrabOne
(
name
);
}
/// <summary>
/// 停止连续抓取
/// </summary>
public
override
void
GrabStop
(
int
index
)
{
_cam
.
GrabStop
(
index
);
}
/// <summary>
/// 关闭所有相机
/// </summary>
public
override
void
CloseAll
()
{
_cam
.
CloseAll
();
}
/// <summary>
/// 关闭相机
/// </summary>
public
override
void
Close
(
int
index
)
{
_cam
.
Close
(
index
);
}
public
override
void
Close
(
string
name
)
{
_cam
.
Close
(
name
);
}
private
static
void
Camera_Continuous_Event
()
{
Continuous_Event
?.
Invoke
();
}
public
override
Bitmap
GrabOneImage
(
string
name
)
{
return
_cam
.
GrabOneImage
(
name
);
}
}
/// <summary>
/// 相机类型
/// </summary>
public
enum
CameraType
{
/// <summary>
/// 海康
/// </summary>
HIK
,
/// <summary>
/// Basle
/// </summary>
Basler
}
public
abstract
class
ClsCamera
{
/// <summary>
/// 所有相机的名称
/// </summary>
protected
List
<
string
>
cameraName
;
protected
string
_errInfo
;
protected
bool
[]
_isOpen
;
protected
int
_count
;
protected
string
[]
_name
;
protected
int
[]
_width
;
protected
int
[]
_height
;
protected
byte
[]
_buffer
;
protected
Bitmap
_image
;
// protected int _index;
public
delegate
void
Continuous
();
public
virtual
string
ErrInfo
=>
_errInfo
;
public
virtual
bool
[]
IsOpen
=>
_isOpen
;
public
virtual
int
Count
=>
_count
;
public
virtual
string
[]
Name
=>
_name
;
public
virtual
int
[]
Width
=>
_width
;
public
virtual
int
[]
Height
=>
_height
;
public
virtual
byte
[]
Buffer
=>
_buffer
;
public
virtual
Bitmap
Image
=>
_image
;
public
abstract
bool
Load
();
public
abstract
bool
OpenAll
();
public
abstract
bool
Open
(
int
index
);
public
abstract
bool
Open
(
string
name
);
public
abstract
void
CloseAll
();
public
abstract
void
Close
(
int
index
);
public
abstract
void
Close
(
string
name
);
// public abstract bool GrabOne();
public
abstract
bool
GrabOne
(
int
index
);
public
abstract
bool
GrabOne
(
string
name
);
// public abstract bool GrabContinuous(int index);
public
abstract
void
GrabStop
(
int
index
);
public
abstract
Bitmap
GrabOneImage
(
string
name
);
}
}
CodeLibraryProject/CodeLibrary/camera/HIK.cs
0 → 100644
查看文件 @
7ce5a30
using
System
;
using
System.Collections.Generic
;
using
System.Drawing
;
using
System.Drawing.Imaging
;
using
System.Runtime.InteropServices
;
using
MvCamCtrl.NET
;
namespace
CodeLibrary
{
partial
class
HIK
:
ClsCamera
{
/// <summary>
/// 当前相机
/// </summary>
private
MyCamera
[]
cameraCurr
;
/// <summary>
/// 所有相机列表
/// </summary>
private
MyCamera
.
MV_CC_DEVICE_INFO_LIST
cameraAll
;
///// <summary>
///// 所有相机的名称
///// </summary>
//private List<string> cameraName;
/// <summary>
/// 连续抓图开始
/// </summary>
private
bool
continuous
;
/// <summary>
/// 连续抓图线程
/// </summary>
private
System
.
Threading
.
Thread
tGrab
;
/// <summary>
/// 连续抓图事件
/// </summary>
public
event
Continuous
Continuous_Event
;
public
override
void
Close
(
int
index
)
{
if
(
cameraCurr
[
index
]
!=
null
)
{
_isOpen
[
index
]
=
false
;
cameraCurr
[
index
].
MV_CC_CloseDevice_NET
();
cameraCurr
[
index
].
MV_CC_DestroyDevice_NET
();
cameraCurr
[
index
]
=
null
;
}
}
public
override
void
Close
(
string
name
)
{
int
index
=
cameraName
.
FindIndex
(
s
=>
s
==
name
);
if
(
index
==
-
1
)
{
_errInfo
=
"Not find"
;
return
;
}
if
(
cameraCurr
[
index
]
!=
null
)
{
_isOpen
[
index
]
=
false
;
cameraCurr
[
index
].
MV_CC_CloseDevice_NET
();
cameraCurr
[
index
].
MV_CC_DestroyDevice_NET
();
cameraCurr
[
index
]
=
null
;
}
}
public
override
void
CloseAll
()
{
for
(
int
i
=
0
;
i
<
cameraCurr
.
Length
;
i
++)
{
if
(
cameraCurr
[
i
]
!=
null
)
{
_isOpen
[
i
]
=
false
;
cameraCurr
[
i
].
MV_CC_CloseDevice_NET
();
cameraCurr
[
i
].
MV_CC_DestroyDevice_NET
();
cameraCurr
[
i
]
=
null
;
}
}
}
//public override bool GrabContinuous(int index)
//{
// if (cameraCurr[index] == null)
// {
// continuous = false;
// _errInfo = "Camera null";
// return false;
// }
// if (continuous) return false;
// int rtn = cameraCurr[index].MV_CC_StartGrabbing_NET();
// if (rtn != MyCamera.MV_OK)
// {
// _errInfo = "Not Start";
// return false;
// }
// tGrab = new System.Threading.Thread(new System.Threading.ThreadStart(FunGrab(index));
// tGrab.Start();
// continuous = true;
// _errInfo = "OK";
// return true;
//}
//public override bool GrabOne()
//{
// if (cameraCurr[_index] == null)
// {
// _errInfo = "Camera null";
// return false;
// }
// try
// {
// int rtn = cameraCurr[_index].MV_CC_StartGrabbing_NET();
// if (rtn != MyCamera.MV_OK)
// {
// _errInfo = "Can not grab one";
// return false;
// }
// ImageCapture(_index);
// _errInfo = "OK";
// return true;
// }
// catch (Exception ex)
// {
// _errInfo = ex.Message;
// return false;
// }
// finally
// {
// cameraCurr[_index].MV_CC_StopGrabbing_NET();
// }
//}
public
override
bool
GrabOne
(
int
index
)
{
if
(
cameraCurr
[
index
]
==
null
)
{
_errInfo
=
"Camera null"
;
return
false
;
}
try
{
int
rtn
=
cameraCurr
[
index
].
MV_CC_StartGrabbing_NET
();
if
(
rtn
!=
MyCamera
.
MV_OK
)
{
_errInfo
=
"Can not grab one"
;
return
false
;
}
ImageCapture
(
index
);
_errInfo
=
"OK"
;
return
true
;
}
catch
(
Exception
ex
)
{
_errInfo
=
ex
.
Message
;
return
false
;
}
finally
{
cameraCurr
[
index
].
MV_CC_StopGrabbing_NET
();
}
}
public
override
bool
GrabOne
(
string
name
)
{
int
idx
=
Array
.
FindIndex
(
_name
,
s
=>
s
==
name
);
if
(
idx
==
-
1
)
return
false
;
else
return
GrabOne
(
idx
);
}
public
override
void
GrabStop
(
int
index
)
{
if
(
tGrab
!=
null
)
tGrab
.
Abort
();
tGrab
=
null
;
continuous
=
false
;
if
(
cameraCurr
==
null
)
return
;
int
rtn
=
cameraCurr
[
index
].
MV_CC_StopGrabbing_NET
();
if
(
rtn
!=
MyCamera
.
MV_OK
)
return
;
}
public
override
bool
Load
()
{
try
{
cameraAll
=
new
MyCamera
.
MV_CC_DEVICE_INFO_LIST
();
int
rtn
=
MyCamera
.
MV_CC_EnumDevices_NET
(
MyCamera
.
MV_GIGE_DEVICE
|
MyCamera
.
MV_USB_DEVICE
,
ref
cameraAll
);
if
(
rtn
!=
MyCamera
.
MV_OK
)
{
_errInfo
=
"Load failed"
;
return
false
;
}
cameraName
=
new
List
<
string
>();
string
s
=
""
;
for
(
int
i
=
0
;
i
<
cameraAll
.
nDeviceNum
;
i
++)
{
MyCamera
.
MV_CC_DEVICE_INFO
device
=
(
MyCamera
.
MV_CC_DEVICE_INFO
)
Marshal
.
PtrToStructure
(
cameraAll
.
pDeviceInfo
[
i
],
typeof
(
MyCamera
.
MV_CC_DEVICE_INFO
));
if
(
device
.
nTLayerType
==
MyCamera
.
MV_GIGE_DEVICE
)
{
IntPtr
buffer
=
Marshal
.
UnsafeAddrOfPinnedArrayElement
(
device
.
SpecialInfo
.
stGigEInfo
,
0
);
MyCamera
.
MV_GIGE_DEVICE_INFO
gigeInfo
=
(
MyCamera
.
MV_GIGE_DEVICE_INFO
)
Marshal
.
PtrToStructure
(
buffer
,
typeof
(
MyCamera
.
MV_GIGE_DEVICE_INFO
));
s
=
"GigE:"
+
gigeInfo
.
chModelName
+
" ("
+
gigeInfo
.
chSerialNumber
+
")"
;
}
else
if
(
device
.
nTLayerType
==
MyCamera
.
MV_USB_DEVICE
)
{
IntPtr
buffer
=
Marshal
.
UnsafeAddrOfPinnedArrayElement
(
device
.
SpecialInfo
.
stUsb3VInfo
,
0
);
MyCamera
.
MV_USB3_DEVICE_INFO
usbInfo
=
(
MyCamera
.
MV_USB3_DEVICE_INFO
)
Marshal
.
PtrToStructure
(
buffer
,
typeof
(
MyCamera
.
MV_USB3_DEVICE_INFO
));
s
=
"USB:"
+
usbInfo
.
chModelName
+
" ("
+
usbInfo
.
chSerialNumber
+
")"
;
}
cameraName
.
Add
(
s
);
}
_name
=
cameraName
.
ToArray
();
_count
=
cameraName
.
Count
;
_isOpen
=
new
bool
[
_count
];
_width
=
new
int
[
_count
];
_height
=
new
int
[
_count
];
cameraCurr
=
new
MyCamera
[
_count
];
_errInfo
=
"OK"
;
return
true
;
}
catch
(
Exception
ex
)
{
_errInfo
=
ex
.
Message
;
return
false
;
}
}
public
override
bool
Open
(
int
index
)
{
// _index = index;
if
(
index
<
0
||
index
>=
_count
)
{
_errInfo
=
"Not find"
;
return
false
;
}
if
(
cameraCurr
[
index
]
!=
null
)
Close
(
index
);
try
{
MyCamera
.
MV_CC_DEVICE_INFO
device
=
(
MyCamera
.
MV_CC_DEVICE_INFO
)
Marshal
.
PtrToStructure
(
cameraAll
.
pDeviceInfo
[
index
],
typeof
(
MyCamera
.
MV_CC_DEVICE_INFO
));
cameraCurr
[
index
]
=
new
MyCamera
();
int
nRet
=
cameraCurr
[
index
].
MV_CC_CreateDevice_NET
(
ref
device
);
if
(
nRet
!=
MyCamera
.
MV_OK
)
return
false
;
nRet
=
cameraCurr
[
index
].
MV_CC_OpenDevice_NET
();
if
(
nRet
!=
MyCamera
.
MV_OK
)
{
cameraCurr
[
index
].
MV_CC_DestroyDevice_NET
();
_errInfo
=
"Can not open"
;
return
false
;
}
if
(
device
.
nTLayerType
==
MyCamera
.
MV_GIGE_DEVICE
)
{
int
nPacketSize
=
cameraCurr
[
index
].
MV_CC_GetOptimalPacketSize_NET
();
if
(
nPacketSize
>
0
)
nRet
=
cameraCurr
[
index
].
MV_CC_SetIntValue_NET
(
"GevSCPSPacketSize"
,
(
uint
)
nPacketSize
);
}
//cameraCurr[index].MV_CC_SetEnumValue_NET("AcquisitionMode", 2); //工作在连续模式
cameraCurr
[
index
].
MV_CC_SetEnumValue_NET
(
"TriggerMode"
,
0
);
//连续模式
MyCamera
.
MVCC_INTVALUE
pstValue
=
new
MyCamera
.
MVCC_INTVALUE
();
nRet
=
cameraCurr
[
index
].
MV_CC_GetWidth_NET
(
ref
pstValue
);
_width
[
index
]
=
(
int
)
pstValue
.
nCurValue
;
nRet
=
cameraCurr
[
index
].
MV_CC_GetHeight_NET
(
ref
pstValue
);
_height
[
index
]
=
(
int
)
pstValue
.
nCurValue
;
_isOpen
[
index
]
=
true
;
_errInfo
=
"OK"
;
return
true
;
}
catch
(
Exception
ex
)
{
HDLogUtil
.
error
(
"打开相机出错:"
+
ex
.
ToString
());
_errInfo
=
ex
.
Message
;
return
false
;
}
}
public
override
bool
Open
(
string
name
)
{
int
n
=
cameraName
.
FindIndex
(
s
=>
s
==
name
);
if
(
n
==
-
1
)
{
_errInfo
=
name
+
"Not find"
;
return
false
;
}
else
return
Open
(
n
);
}
public
override
Bitmap
GrabOneImage
(
string
name
)
{
int
n
=
cameraName
.
FindIndex
(
s
=>
s
==
name
);
if
(
n
==
-
1
)
{
_errInfo
=
name
+
"Not find"
;
return
null
;
}
if
(
cameraCurr
[
n
]
!=
null
)
{
}
else
{
Open
(
name
);
}
GrabOne
(
name
);
return
Image
;
}
public
override
bool
OpenAll
()
{
bool
rtn
=
true
;
for
(
int
i
=
0
;
i
<
cameraName
.
Count
;
i
++)
{
rtn
=
Open
(
i
);
if
(!
rtn
)
break
;
}
return
rtn
;
}
//private void FunGrab(int index)
//{
// while (true)
// {
// ImageCapture(index);
// System.Threading.Thread.Sleep(50);
// Continuous_Event?.Invoke();
// System.Threading.Thread.Sleep(100);
// }
//}
private
void
ImageCapture
(
int
index
)
{
MyCamera
.
MVCC_INTVALUE
stParam
=
new
MyCamera
.
MVCC_INTVALUE
();
int
rtn
=
cameraCurr
[
index
].
MV_CC_GetIntValue_NET
(
"PayloadSize"
,
ref
stParam
);
if
(
rtn
!=
MyCamera
.
MV_OK
)
return
;
uint
dataSize
=
stParam
.
nCurValue
;
byte
[]
dataArr
=
new
byte
[
dataSize
];
uint
buffSize
=
dataSize
*
3
+
2048
;
byte
[]
buffArr
=
new
byte
[
buffSize
];
IntPtr
pData
=
Marshal
.
UnsafeAddrOfPinnedArrayElement
(
dataArr
,
0
);
MyCamera
.
MV_FRAME_OUT_INFO_EX
stFrameInfo
=
new
MyCamera
.
MV_FRAME_OUT_INFO_EX
();
rtn
=
cameraCurr
[
index
].
MV_CC_GetOneFrameTimeout_NET
(
pData
,
dataSize
,
ref
stFrameInfo
,
100000
);
if
(
rtn
!=
MyCamera
.
MV_OK
)
return
;
MyCamera
.
MvGvspPixelType
enDstPixelType
=
stFrameInfo
.
enPixelType
;
switch
(
stFrameInfo
.
enPixelType
)
{
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_Mono8
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_Mono10
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_Mono10_Packed
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_Mono12
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_Mono12_Packed
:
enDstPixelType
=
stFrameInfo
.
enPixelType
;
break
;
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_BayerGR8
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_BayerRG8
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_BayerGB8
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_BayerBG8
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_BayerGR10
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_BayerRG10
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_BayerGB10
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_BayerBG10
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_BayerGR12
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_BayerRG12
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_BayerGB12
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_BayerBG12
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_BayerGR10_Packed
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_BayerRG10_Packed
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_BayerGB10_Packed
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_BayerBG10_Packed
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_BayerGR12_Packed
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_BayerRG12_Packed
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_BayerGB12_Packed
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_BayerBG12_Packed
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_RGB8_Packed
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_YUV422_Packed
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_YUV422_YUYV_Packed
:
case
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_YCBCR411_8_CBYYCRYY
:
enDstPixelType
=
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_RGB8_Packed
;
break
;
}
IntPtr
pImage
=
Marshal
.
UnsafeAddrOfPinnedArrayElement
(
buffArr
,
0
);
MyCamera
.
MV_PIXEL_CONVERT_PARAM
stConverPixelParam
=
new
MyCamera
.
MV_PIXEL_CONVERT_PARAM
();
stConverPixelParam
.
nWidth
=
stFrameInfo
.
nWidth
;
stConverPixelParam
.
nHeight
=
stFrameInfo
.
nHeight
;
stConverPixelParam
.
pSrcData
=
pData
;
stConverPixelParam
.
nSrcDataLen
=
stFrameInfo
.
nFrameLen
;
stConverPixelParam
.
enSrcPixelType
=
stFrameInfo
.
enPixelType
;
stConverPixelParam
.
enDstPixelType
=
enDstPixelType
;
stConverPixelParam
.
pDstBuffer
=
pImage
;
stConverPixelParam
.
nDstBufferSize
=
buffSize
;
rtn
=
cameraCurr
[
index
].
MV_CC_ConvertPixelType_NET
(
ref
stConverPixelParam
);
if
(
rtn
!=
MyCamera
.
MV_OK
)
return
;
if
(
enDstPixelType
==
MyCamera
.
MvGvspPixelType
.
PixelType_Gvsp_Mono8
)
{
_image
=
new
Bitmap
(
stFrameInfo
.
nWidth
,
stFrameInfo
.
nHeight
,
stFrameInfo
.
nWidth
*
1
,
PixelFormat
.
Format8bppIndexed
,
pImage
);
ColorPalette
cp
=
Image
.
Palette
;
for
(
int
i
=
0
;
i
<
256
;
i
++)
cp
.
Entries
[
i
]
=
Color
.
FromArgb
(
i
,
i
,
i
);
Image
.
Palette
=
cp
;
int
picSize
=
Image
.
Width
*
Image
.
Height
;
_buffer
=
new
byte
[
picSize
];
Array
.
Copy
(
buffArr
,
Buffer
,
picSize
);
//Rectangle rect = new Rectangle(0, 0, Image.Width, Image.Height);
//BitmapData bmpData = Image.LockBits(rect, ImageLockMode.ReadWrite, Image.PixelFormat);
//IntPtr iPtr = bmpData.Scan0;
//int picSize = Image.Width * Image.Height;
//Buffer = new byte[picSize];
//Marshal.Copy(iPtr, Buffer, 0, picSize);
//Image.UnlockBits(bmpData);
}
else
{
for
(
int
i
=
0
;
i
<
stFrameInfo
.
nHeight
;
i
++)
{
for
(
int
j
=
0
;
j
<
stFrameInfo
.
nWidth
;
j
++)
{
byte
chRed
=
buffArr
[
i
*
stFrameInfo
.
nWidth
*
3
+
j
*
3
];
buffArr
[
i
*
stFrameInfo
.
nWidth
*
3
+
j
*
3
]
=
buffArr
[
i
*
stFrameInfo
.
nWidth
*
3
+
j
*
3
+
2
];
buffArr
[
i
*
stFrameInfo
.
nWidth
*
3
+
j
*
3
+
2
]
=
chRed
;
}
}
_image
=
new
Bitmap
(
stFrameInfo
.
nWidth
,
stFrameInfo
.
nHeight
,
stFrameInfo
.
nWidth
*
3
,
PixelFormat
.
Format24bppRgb
,
pImage
);
int
picSize
=
Image
.
Width
*
Image
.
Height
*
3
;
_buffer
=
new
byte
[
picSize
];
Array
.
Copy
(
buffArr
,
Buffer
,
picSize
);
}
}
}
}
\ No newline at end of file
CodeLibraryProject/CodeTest/CodeCreater.cs
查看文件 @
7ce5a30
...
...
@@ -25,7 +25,7 @@ namespace CodeTest
}
for
(
int
i
=
100000
;
i
<=
100000
+
count
;
i
++)
{
string
name
=
"
pn;"
+
i
.
ToString
().
PadLeft
(
6
,
'0'
)
+
";1000
"
;
string
name
=
"
TRAY"
+
i
.
ToString
().
PadLeft
(
6
,
'0'
)
+
"
"
;
Bitmap
map
=
ZXingCode
(
name
,
200
,
BarcodeFormat
.
QR_CODE
);
if
(
map
!=
null
)
{
...
...
CodeLibraryProject/CodeTest/Program.cs
查看文件 @
7ce5a30
...
...
@@ -18,12 +18,12 @@ namespace CodeTest
[
STAThread
]
static
void
Main
()
{
//
CodeCreater.CreateCode(10
0);
//
CodeCreater.CreateCode(1
0);
Application
.
EnableVisualStyles
();
Application
.
SetCompatibleTextRenderingDefault
(
false
);
HDCodeLearnHelper
.
LoadConfig
(
ConfigAppSettings
.
GetValue
(
Setting_Init
.
CameraName
),
ConfigAppSettings
.
GetValue
(
Setting_Init
.
CodeType
));
Application
.
Run
(
new
FrmCodeDecode
());
//Application.Run(new FrmTest());
//
//
Application.Run(new FrmTest());
}
}
...
...
dll/CodeLibrary.dll
0 → 100644
查看文件 @
7ce5a30
此文件类型无法预览
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论