I'm trying to generate a barcode using ZXing.NET for dot net core asp.net application. I can't figure out how to display text with the barcode and documentation seems to be really, really lacking. Does anyone have an idea how to make it work?
This is the code I have (mostly taken from another post on 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");
}
}
This gets me a barcode, but no content.
Or, suggestions of better/easier to use/better-documented libraries would be appreciated too.