Asa_ZXing.cs
2.0 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
using System;
using System.Collections.Generic;
using System.Drawing;
using ZXing;
using ZXing.Common;
using ZXing.Datamatrix;
namespace Asa
{
public class ZXingCode
{
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 Bitmap DataMatrix(string text, int size)
{
if (size < 10) size = 10;
//DatamatrixEncodingOptions dmxoption = new DatamatrixEncodingOptions();
//dmxoption.Height = size;
//dmxoption.Width = size;
//dmxoption.Margin = 10;
//dmxoption.PureBarcode = false;
//dmxoption.SymbolShape = ZXing.Datamatrix.Encoder.SymbolShapeHint.FORCE_NONE;
//BarcodeWriter barcodewriter = new BarcodeWriter();
//barcodewriter.Options = dmxoption;
//barcodewriter.Format = BarcodeFormat.DATA_MATRIX;
//return barcodewriter.Write(text);
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;
}
}
}