LEADTOOLS Support
Document
Document SDK Examples
HOW TO: Read/Write barcodes using LEADTOOLS .NET Standard libraries
#1
Posted
:
Thursday, November 16, 2017 9:03:19 AM(UTC)
Groups: Tech Support
Posts: 366
Thanks: 1 times
Was thanked: 4 time(s) in 4 post(s)
Attached is a small .NET Core application written in C# using the LEADTOOLS 20 Barcode (.NET Standard) nuget package. This simple application generates an image with a QR code, outputs the image to a memory stream, and then reads the resulting MemoryStream to easily verify the encoding was done correctly.
The following sample code illustrates how a simple services could be written to process barcodes. Here's code illustrating barcode writing:
Code:
// Figure out how big to make the image
barcodeEngineInstance.Writer.CalculateBarcodeDataBounds(LeadRect.Empty, imageResolution, imageResolution, qrData, qrWriteOptions);
imageHeight = qrData.Bounds.Height;
imageWidth = qrData.Bounds.Width;
// Create an empty image
barcodeImage = new RasterImage(RasterMemoryFlags.Conventional, imageWidth, imageHeight, bitsPerPixel, RasterByteOrder.Rgb,
RasterViewPerspective.TopLeft, palette, IntPtr.Zero, userDataLength);
// Make the image all white
FillCommand fillCmd = new FillCommand(RasterColor.White);
fillCmd.Run(barcodeImage);
// Write the barcode
barcodeEngineInstance.Writer.WriteBarcode(barcodeImage, qrData, qrWriteOptions);
// Save the results
codecs.Save(barcodeImage, barcodeOutputStream, RasterImageFormat.CcittGroup4, bitsPerPixel);
And here's code illustrating barcode reading:
Code:
// Decode the stream
barcodeImage = codecs.Load(inputStream, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1);
// Check for barcodes
dataArray = barcodeEngineInstance.Reader.ReadBarcodes(barcodeImage, LeadRect.Empty, 0, null);
// Get the barcode data to output
StringBuilder sb = new StringBuilder();
sb.AppendFormat("{0} barcode(s) found", dataArray.Length);
sb.AppendLine();
for (int i = 0; i < dataArray.Length; i++)
{
BarcodeData data = dataArray[i];
sb.AppendFormat("Symbology: {0}, Location: {1}, Data: {2}", data.Symbology.ToString(), data.Bounds.ToString(), data.Value);
sb.AppendLine();
}
Before running this application, please update the DEVELOPER_LIC and DEVELOPER_KEY class members to point to your license files.
Edited by moderator Thursday, November 16, 2017 4:13:44 PM(UTC)
| Reason: Not specified
Walter Bates
Senior Support Engineer
LEAD Technologies, Inc.
LEADTOOLS Support
Document
Document SDK Examples
HOW TO: Read/Write barcodes using LEADTOOLS .NET Standard libraries
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.