Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
孙克
/
GeneralClassLibrary
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 70114bfb
由
几米阳光
编写于
2019-03-06 13:13:54 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
调试修改
1 个父辈
941dda78
显示空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
199 行增加
和
12 行删除
CodeLibraryProject/CodeLibrary/FrmCodeDecode.Designer.cs
CodeLibraryProject/CodeLibrary/FrmCodeDecode.cs
CodeLibraryProject/CodeTest/App.config
CodeLibraryProject/CodeTest/CodeCreater.cs
CodeLibraryProject/CodeTest/CodeTest.csproj
CodeLibraryProject/CodeTest/Program.cs
CodeLibraryProject/编译好的DLL/CodeLibrary.dll
CodeLibraryProject/CodeLibrary/FrmCodeDecode.Designer.cs
查看文件 @
70114bf
...
...
@@ -54,6 +54,7 @@
this
.
txtParamPath
=
new
System
.
Windows
.
Forms
.
TextBox
();
this
.
label4
=
new
System
.
Windows
.
Forms
.
Label
();
this
.
btnLight
=
new
System
.
Windows
.
Forms
.
Button
();
this
.
button1
=
new
System
.
Windows
.
Forms
.
Button
();
((
System
.
ComponentModel
.
ISupportInitialize
)(
this
.
pictureBox1
)).
BeginInit
();
this
.
SuspendLayout
();
//
...
...
@@ -353,11 +354,24 @@
this
.
btnLight
.
Visible
=
false
;
this
.
btnLight
.
Click
+=
new
System
.
EventHandler
(
this
.
btnLigth_Click
);
//
// button1
//
this
.
button1
.
Font
=
new
System
.
Drawing
.
Font
(
"微软雅黑"
,
9F
,
System
.
Drawing
.
FontStyle
.
Regular
,
System
.
Drawing
.
GraphicsUnit
.
Point
,
((
byte
)(
134
)));
this
.
button1
.
Location
=
new
System
.
Drawing
.
Point
(
723
,
12
);
this
.
button1
.
Name
=
"button1"
;
this
.
button1
.
Size
=
new
System
.
Drawing
.
Size
(
167
,
33
);
this
.
button1
.
TabIndex
=
29
;
this
.
button1
.
Text
=
"循环测试"
;
this
.
button1
.
UseVisualStyleBackColor
=
true
;
this
.
button1
.
Visible
=
false
;
this
.
button1
.
Click
+=
new
System
.
EventHandler
(
this
.
button1_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
.
Controls
.
Add
(
this
.
button1
);
this
.
Controls
.
Add
(
this
.
txtParamPath
);
this
.
Controls
.
Add
(
this
.
label4
);
this
.
Controls
.
Add
(
this
.
chbUseParam
);
...
...
@@ -422,6 +436,7 @@
private
System
.
Windows
.
Forms
.
TextBox
txtParamPath
;
private
System
.
Windows
.
Forms
.
Label
label4
;
private
System
.
Windows
.
Forms
.
Button
btnLight
;
private
System
.
Windows
.
Forms
.
Button
button1
;
}
}
CodeLibraryProject/CodeLibrary/FrmCodeDecode.cs
查看文件 @
70114bf
...
...
@@ -34,7 +34,7 @@ namespace CodeLibrary
private
string
sureDelete
=
CodeResourceControl
.
GetString
(
CodeResourceControl
.
sureDelete
,
"确定删除文件:"
);
private
void
FrmMain_Load
(
object
sender
,
EventArgs
e
)
{
Control
.
CheckForIllegalCrossThreadCalls
=
false
;
cmbCount
.
SelectedIndex
=
0
;
LoadCamera
();
...
...
@@ -284,5 +284,69 @@ namespace CodeLibrary
txtParamPath
.
Text
=
HDCodeHelper
.
GetCodeParamFilePath
(
cmbCodeType
.
Text
);
}
}
private
System
.
Timers
.
Timer
testTimer
=
new
System
.
Timers
.
Timer
();
private
int
testCount
=
0
;
private
void
button1_Click
(
object
sender
,
EventArgs
e
)
{
if
(
testTimer
.
Enabled
)
{
HDLogUtil
.
info
(
"停止扫码测试"
);
testTimer
.
Stop
();
}
else
{
HDLogUtil
.
info
(
"开始扫码测试"
);
testCount
=
0
;
testTimer
.
Interval
=
1000
;
testTimer
.
Elapsed
+=
TestTimer_Elapsed
;
testTimer
.
AutoReset
=
true
;
testTimer
.
Start
();
}
}
private
void
TestTimer_Elapsed
(
object
sender
,
System
.
Timers
.
ElapsedEventArgs
e
)
{
try
{
if
(
pictureBox1
.
Image
==
null
)
{
return
;
}
int
count
=
cmbCount
.
SelectedIndex
+
1
;
txtResult
.
Text
=
""
;
stopwatch
.
Restart
();
testCount
++;
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
);
}
else
{
codeList
=
HDCodeHelper
.
DecodeCode
(
ho_image
,
count
,
codeParamPath
,
cmbCodeType
.
Text
);
}
ShowCode
(
codeList
);
txtResult
.
Text
+=
"\r\n elapsed time:"
+
stopwatch
.
Elapsed
.
ToString
();
HDLogUtil
.
info
(
"第【"
+
testCount
+
"】次扫码测试结束"
);
}
catch
(
Exception
ex
)
{
HDLogUtil
.
error
(
ex
.
ToString
());
}
}
}
}
CodeLibraryProject/CodeTest/App.config
查看文件 @
70114bf
...
...
@@ -9,13 +9,13 @@
<!--是否开机自动启动料仓-->
<
add
key
=
"App_AutoRun"
value
=
"0"
/>
<!--摄像机名称列表配置,用
#分割-->
<
add
key
=
"CameraName"
value
=
"[0] Integrated Camera"
/>
<
add
key
=
"CameraName"
value
=
"[0] Integrated Camera"
/>
<!--<
add
key
=
"CameraName"
value
=
"tsavCamera"
/>-->
<!--<
add
key
=
"CameraName"
value
=
"codeCamera"
/>-->
<!--二维码类型列表配置,用
#分割-->
<
add
key
=
"CodeType"
value
=
"Data Matrix ECC 200#QR Code"
/>
<
add
key
=
"CodeType"
value
=
"Data Matrix ECC 200#QR Code"
/>
<!--二维码参数文件所在路径,文件名与二维码类型名一样-->
<
add
key
=
"CodeParamPath"
value
=
"\Conifg\"
/>
<
add
key
=
"CodeParamPath"
value
=
"\Conifg\"
/>
</
appSettings
>
<
log4net
>
<
appender
name
=
"RollingLogFileAppender"
type
=
"log4net.Appender.RollingFileAppender"
>
...
...
@@ -33,7 +33,7 @@
</
root
>
</
log4net
>
<
startup
>
<
supportedRuntime
version
=
"v4.0"
sku
=
".NETFramework,Version=v4.
0
"
/>
<
supportedRuntime
version
=
"v4.0"
sku
=
".NETFramework,Version=v4.
6.1
"
/>
</
startup
>
</
configuration
>
CodeLibraryProject/CodeTest/CodeCreater.cs
0 → 100644
查看文件 @
70114bf
using
System
;
using
System.Collections.Generic
;
using
System.Drawing
;
using
System.Drawing.Imaging
;
using
System.IO
;
using
System.Linq
;
using
System.Text
;
using
ZXing
;
using
ZXing.Common
;
namespace
CodeTest
{
public
class
CodeCreater
{
public
static
void
CreateCode
(
int
count
)
{
DateTime
now
=
DateTime
.
Now
;
string
data
=
now
.
Year
.
ToString
()
+
now
.
Month
.
ToString
().
PadLeft
(
2
,
'0'
)
+
now
.
Day
.
ToString
().
PadLeft
(
2
,
'0'
)
+
now
.
Hour
.
ToString
().
PadLeft
(
2
,
'0'
);
string
targetFilePath
=
@"D:\Code\" + data + @"
\
";
if
(!
File
.
Exists
(
targetFilePath
))
{
Directory
.
CreateDirectory
(
targetFilePath
);
}
for
(
int
i
=
1
;
i
<=
count
;
i
++)
{
string
name
=
"pn;"
+
i
.
ToString
().
PadLeft
(
6
,
'0'
)
+
";1000"
;
Bitmap
map
=
GetQRCodeByZXingNet
(
name
,
200
,
200
);
if
(
map
!=
null
)
{
map
.
Save
(
targetFilePath
+
name
+
".bmp"
);
}
}
}
/// <summary>
/// 生成二维码图片
/// </summary>
/// <param name="strMessage">要生成二维码的字符串</param>
/// <param name="width">二维码图片宽度</param>
/// <param name="height">二维码图片高度</param>
/// <returns></returns>
private
static
Bitmap
GetQRCodeByZXingNet
(
String
strMessage
,
Int32
width
,
Int32
height
)
{
Bitmap
result
=
null
;
try
{
BarcodeWriter
barCodeWriter
=
new
BarcodeWriter
();
barCodeWriter
.
Format
=
BarcodeFormat
.
QR_CODE
;
barCodeWriter
.
Options
.
Hints
.
Add
(
EncodeHintType
.
CHARACTER_SET
,
"UTF-8"
);
barCodeWriter
.
Options
.
Hints
.
Add
(
EncodeHintType
.
ERROR_CORRECTION
,
ZXing
.
QrCode
.
Internal
.
ErrorCorrectionLevel
.
H
);
barCodeWriter
.
Options
.
Height
=
height
;
barCodeWriter
.
Options
.
Width
=
width
;
barCodeWriter
.
Options
.
Margin
=
0
;
ZXing
.
Common
.
BitMatrix
bm
=
barCodeWriter
.
Encode
(
strMessage
);
result
=
barCodeWriter
.
Write
(
bm
);
}
catch
(
Exception
ex
)
{
//异常输出
}
return
result
;
}
//public bool DecodeQRCode(Bitmap bmp, out string text)
//{
// DecodingOptions option = new DecodingOptions();
// //option.PossibleFormats = new List<BarcodeFormat>() { BarcodeFormat.QR_CODE, BarcodeFormat.All_1D };
// option.PossibleFormats = new List<BarcodeFormat>() { BarcodeFormat.QR_CODE };
// BarcodeReader br = new BarcodeReader();
// br.Options = option;
// Result rs = br.Decode(bmp);
// if (rs == null)
// {
// text = "";
// return false;
// }
// else
// {
// text = rs.Text;
// return true;
// }
//}
///// <summary>
///// DataMatrix矩阵二维码
///// </summary>
///// <param name="text"></param>
///// <param name="size"></param>
///// <returns></returns>
//public static Bitmap DataMatrix(string text, int size)
//{
// if (size < 10) size = 10;
// DataMatrix.net.DmtxImageEncoderOptions opt = new DataMatrix.net.DmtxImageEncoderOptions();
// opt.ModuleSize = size;
// opt.MarginSize = 5;
// DataMatrix.net.DmtxImageEncoder encoder = new DataMatrix.net.DmtxImageEncoder();
// Bitmap bm = encoder.EncodeImage(text, opt);
// return bm;
//}
}
}
CodeLibraryProject/CodeTest/CodeTest.csproj
查看文件 @
70114bf
...
...
@@ -8,7 +8,7 @@
<OutputType>WinExe</OutputType>
<RootNamespace>CodeTest</RootNamespace>
<AssemblyName>CodeTest</AssemblyName>
<TargetFrameworkVersion>v4.
0
</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.
6.1
</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<TargetFrameworkProfile />
...
...
@@ -40,6 +40,9 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\dll\Basler.Pylon.dll</HintPath>
</Reference>
<Reference Include="DataMatrix.net">
<HintPath>..\dll\DataMatrix.net.dll</HintPath>
</Reference>
<Reference Include="halcondotnet">
<HintPath>..\dll\halcondotnet.dll</HintPath>
</Reference>
...
...
@@ -58,11 +61,13 @@
<Reference Include="System.Net.Http" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="zxing">
<Reference Include="zxing, Version=0.14.1.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\dll\zxing.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="CodeCreater.cs" />
<Compile Include="CompressHelper.cs" />
<Compile Include="FrmTest.cs">
<SubType>Form</SubType>
...
...
CodeLibraryProject/CodeTest/Program.cs
查看文件 @
70114bf
...
...
@@ -3,6 +3,7 @@ using Common;
using
log4net.Config
;
using
System
;
using
System.Collections.Generic
;
using
System.Drawing
;
using
System.Linq
;
using
System.Threading.Tasks
;
using
System.Windows.Forms
;
...
...
@@ -17,12 +18,13 @@ namespace CodeTest
[
STAThread
]
static
void
Main
()
{
Application
.
EnableVisualStyles
();
Application
.
SetCompatibleTextRenderingDefault
(
false
);
HDCodeLearnHelper
.
LoadConfig
(
ConfigAppSettings
.
GetValue
(
Setting_Init
.
CameraName
),
ConfigAppSettings
.
GetValue
(
Setting_Init
.
CodeType
));
Application
.
Run
(
new
FrmCodeDecode
());
CodeCreater
.
CreateCode
(
30
);
//
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());
}
}
}
CodeLibraryProject/编译好的DLL/CodeLibrary.dll
查看文件 @
70114bf
此文件类型无法预览
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论