一.使用 ZXing.Net 库
先通过 NuGet 包管理器安装安装 ZXing.Net库。
有两种设置条码规格的方法
方法一
// 创建条形码生成器
BarcodeWriter wr = new BarcodeWriter();
// 设置条形码规格
EncodingOptions encodeOption = new EncodingOptions();
encodeOption.Height = 240; // 必须制定高度、宽度
encodeOption.Width = 560;
encodeOption.Margin = 10;
wr.Options = encodeOption; // 应用编码选项
// 设置条形码格式(例如 CODE_128, QR_CODE 等)
wr.Format = BarcodeFormat.CODE_128; // 设置条形码格式
方法二
int width = 240; // 条形码的宽度
int height = 150; // 条形码的高度
BarcodeWriter wr= new BarcodeWriter
{
Format = BarcodeFormat.CODE_128,
Options = new ZXing.Common.EncodingOptions
{
Width = width,
Height = height,
//PureBarcode = true, // 设置为纯条形码模式
Margin = 10, // 设置总体边距为0
PureBarcode = false, // 设置为非纯