我在 ASP.NET Core 5.0 应用程序中使用ZXing.Net.Bindings.ImageSharp来生成 Code128 条形码。 0.16.9-beta
我的问题是我无法让代码在条形码下方生成文本标签 - 即使PureBarcode = false
已指定。
我创建了两种测试方法:
- 第一种方法不使用ImageSharp,而是使用
System.Drawing
. 此方法GetBarcode("123")
按预期工作并生成带有以下文本标签的条形码:
- 第二种方法使用
ImageSharp
. 但是,此方法GetBarcodeImageSharp("123")
不会生成带有以下文本标签的条形码:
我究竟做错了什么?
[HttpGet]
[Route("~/getbarcode")]
public void GetBarcode(string barcode)
{
BarcodeWriter writer = new BarcodeWriter
{
Format = BarcodeFormat.CODE_128,
Options = new EncodingOptions
{
Height = 100,
Width = 300,
Margin = 0,
PureBarcode = false
}
};
writer.Write(barcode).Save(@$"C:\Web\{barcode}.jpg", ImageFormat.Jpeg);
}
[HttpGet]
[Route("~/getbarcodeimagesharp")]
public void GetBarcodeImageSharp(string barcode)
{
var barcodeWriter = new ZXing.ImageSharp.BarcodeWriter<Rgba32>
{
Format = ZXing.BarcodeFormat.CODE_128,
Options = new EncodingOptions // have also tried with Code128EncodingOptions but no luck
{
Height = 100,
Width = 300,
Margin = 0,
PureBarcode = false
}
};
barcodeWriter.Write(barcode).Save(@$"C:\Web\{barcode}-imagesharp.jpg");
}