上传者: ksig188
|
上传时间: 2022-06-14 18:25:28
|
文件大小: 203KB
|
文件类型: ZIP
直接添加引用zxing.dll,调用如下方法生成Bitmap然后可以打印或显示出来:
private Bitmap GetQRCodeByZXingNet(String strMessage, Int32 width, Int32 height)
{
Bitmap result = null;
try
{
BarcodeWriter barCodeWriter = new BarcodeWriter();
barCodeWriter.Format = BarcodeFormat.CODE_128;
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)
{
//异常输出
MessageBox.Show(ex.Message);
}
return result;
}