我正在尝试使用 ZXing.NET 为 dot net core asp.net 应用程序生成条形码。我不知道如何用条形码显示文本,而且文档似乎真的非常非常缺乏。有谁知道如何使它工作?
这是我拥有的代码(主要取自 SO 上的另一篇文章):
BarcodeWriterPixelData writer = new BarcodeWriterPixelData()
{
Format = BarcodeFormat.CODE_128,
Options = new EncodingOptions
{
Height = 400,
Width = 800,
PureBarcode = false, // this should indicate that the text should be displayed, in theory. Makes no difference, though.
Margin = 10
}
};
var pixelData = writer.Write("test text");
using (var bitmap = new Bitmap(pixelData.Width, pixelData.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb))
{
using (var ms = new System.IO.MemoryStream())
{
var bitmapData = bitmap.LockBits(new Rectangle(0, 0, pixelData.Width, pixelData.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
try
{
System.Runtime.InteropServices.Marshal.Copy(pixelData.Pixels, 0, bitmapData.Scan0, pixelData.Pixels.Length);
}
finally
{
bitmap.UnlockBits(bitmapData);
}
bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
return File(ms.ToArray(), "image/jpeg");
}
}
这给了我一个条形码,但没有内容。
或者,更好/更容易使用/记录更好的库的建议也将不胜感激。