Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
孙克
/
GeneralClassLibrary
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit e91fec9c
由
几米阳光
编写于
2019-03-08 16:13:44 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
1
1 个父辈
70114bfb
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
71 行增加
和
31 行删除
CodeLibraryProject/CodeTest/CodeCreater.cs
CodeLibraryProject/CodeTest/Program.cs
CodeLibraryProject/Common/Common.csproj
CodeLibraryProject/CodeTest/CodeCreater.cs
查看文件 @
e91fec9
...
@@ -7,6 +7,7 @@ using System.Linq;
...
@@ -7,6 +7,7 @@ using System.Linq;
using
System.Text
;
using
System.Text
;
using
ZXing
;
using
ZXing
;
using
ZXing.Common
;
using
ZXing.Common
;
using
ZXing.QrCode
;
namespace
CodeTest
namespace
CodeTest
{
{
...
@@ -25,42 +26,63 @@ namespace CodeTest
...
@@ -25,42 +26,63 @@ namespace CodeTest
for
(
int
i
=
1
;
i
<=
count
;
i
++)
for
(
int
i
=
1
;
i
<=
count
;
i
++)
{
{
string
name
=
"pn;"
+
i
.
ToString
().
PadLeft
(
6
,
'0'
)
+
";1000"
;
string
name
=
"pn;"
+
i
.
ToString
().
PadLeft
(
6
,
'0'
)
+
";1000"
;
Bitmap
map
=
GetQRCodeByZXingNet
(
name
,
200
,
200
);
Bitmap
map
=
ZXingCode
(
name
,
200
,
BarcodeFormat
.
QR_CODE
);
if
(
map
!=
null
)
if
(
map
!=
null
)
{
{
map
.
Save
(
targetFilePath
+
name
+
".bmp"
);
map
.
Save
(
targetFilePath
+
name
+
".bmp"
);
}
}
}
}
}
}
public
static
Bitmap
ZXingCode
(
string
msg
,
int
codeSizeInPixels
,
BarcodeFormat
type
)
/// <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
;
if
(
codeSizeInPixels
<=
0
)
try
{
{
BarcodeWriter
barCodeWriter
=
new
BarcodeWriter
();
codeSizeInPixels
=
10
;
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
)
BarcodeWriter
writer
=
new
BarcodeWriter
();
{
writer
.
Format
=
type
;
//异常输出
}
QrCodeEncodingOptions
options
=
new
QrCodeEncodingOptions
();
return
result
;
options
.
DisableECI
=
true
;
//设置内容编码
options
.
CharacterSet
=
"UTF-8"
;
//设置二维码的宽度和高度
options
.
Width
=
codeSizeInPixels
;
options
.
Height
=
codeSizeInPixels
;
//设置二维码的边距,单位不是固定像素
options
.
Margin
=
1
;
writer
.
Options
=
options
;
Bitmap
map
=
writer
.
Write
(
msg
);
return
map
;
}
}
///// <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)
//public bool DecodeQRCode(Bitmap bmp, out string text)
//{
//{
// DecodingOptions option = new DecodingOptions();
// DecodingOptions option = new DecodingOptions();
...
...
CodeLibraryProject/CodeTest/Program.cs
查看文件 @
e91fec9
...
@@ -18,11 +18,11 @@ namespace CodeTest
...
@@ -18,11 +18,11 @@ namespace CodeTest
[
STAThread
]
[
STAThread
]
static
void
Main
()
static
void
Main
()
{
{
CodeCreater
.
CreateCode
(
30
);
//
CodeCreater.CreateCode(30);
//
Application.EnableVisualStyles();
Application
.
EnableVisualStyles
();
//
Application.SetCompatibleTextRenderingDefault(false);
Application
.
SetCompatibleTextRenderingDefault
(
false
);
//HDCodeLearnHelper.LoadConfig(ConfigAppSettings.GetValue(Setting_Init.CameraName),
ConfigAppSettings.GetValue(Setting_Init.CodeType));
HDCodeLearnHelper
.
LoadConfig
(
ConfigAppSettings
.
GetValue
(
Setting_Init
.
CameraName
),
ConfigAppSettings
.
GetValue
(
Setting_Init
.
CodeType
));
//
Application.Run(new FrmCodeDecode());
Application
.
Run
(
new
FrmCodeDecode
());
//Application.Run(new FrmTest());
//Application.Run(new FrmTest());
}
}
...
...
CodeLibraryProject/Common/Common.csproj
查看文件 @
e91fec9
...
@@ -32,6 +32,24 @@
...
@@ -32,6 +32,24 @@
<WarningLevel>4</WarningLevel>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<ItemGroup>
<Reference Include="log4net, Version=1.2.15.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<Reference Include="log4net, Version=1.2.15.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<SpecificVersion>False</SpecificVersion>
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论