#1
Posted
:
Sunday, January 15, 2017 7:45:30 PM(UTC)
Groups: Registered
Posts: 1
I use the following code to read barcode (QR) and I am getting zero result for the attached PDF/PNGs. I tried passing in additional parameters such as symbology, readeroptions but still the results are empty for this image. However, I could see the same image getting parsed/working in Leadtools demo site.
http://demo.leadtools.co...cript/Barcode/index.htmlCould you please review and let me know what I am missing? I would really appreciate your response!
Code:// Load the image
using (RasterCodecs codecs = new RasterCodecs())
{
using (RasterImage image = codecs.Load(resourceDirectory + @"\FaxInput\barcodeimage.png", 0, CodecsLoadByteOrder.BgrOrGray, 1, 1))
{
QRBarcodeReadOptions qrReadOptions = reader.GetDefaultOptions(BarcodeSymbology.QR).Clone() as QRBarcodeReadOptions;
BarcodeReadOptions[] readOptions = { qrReadOptions };
// Read all the barcodes in this image
BarcodeData data = engine.Reader.ReadBarcode(image, LogicalRectangle.Empty, BarcodeSymbology.Unknown);
//BarcodeData[] barcodes = reader.ReadBarcodes(image, LogicalRectangle.Empty, 0, null, null);
//barcodes = reader.ReadBarcodes(image, LogicalRectangle.Empty, 0, null, options);
if (data != null)
{
codeText = data.Value;
}
}
}
Edited by moderator Monday, January 16, 2017 10:31:51 AM(UTC)
| Reason: formatted text
#2
Posted
:
Tuesday, January 17, 2017 11:45:01 AM(UTC)
Groups: Registered, Tech Support, Administrators
Posts: 39
Thanks: 2 times
Was thanked: 3 time(s) in 3 post(s)
rnatarajan,
Looking at the code you shared here I noticed a couple of things missing. I don't see where you instantiate the BarcodeEngine. I realize this code could be in a different part of your code but I'll mention it just to make sure. You may also want to load the files at a higher DPI and set options for QR codes such as EnableDoublePass. I took the code you shared here and added a few options to it, the following successfully processes the images you attached. I will note that barcodeimage.PNG seems like a very low resolution screenshot of the PDF file barcode.
Code:
Code:static void barcodeExample()
{
using (RasterCodecs codecs = new RasterCodecs())
{
//load the document at an ideal DPI
codecs.Options.RasterizeDocument.Load.XResolution = 300;
codecs.Options.RasterizeDocument.Load.YResolution = 300;
//get information from the file on disk, such as total pages
CodecsImageInfo info = codecs.GetInformation(@"..\..\..\testFile.pdf", true);
int totalPages = info.TotalPages;
//loop through each page and process any barcodes using the specified options
for(int i = 1; i <= totalPages; i++)
{
//load image
using (RasterImage image = codecs.Load(@"..\..\..\testFile.pdf", 0, CodecsLoadByteOrder.BgrOrGray, i, i))
{
//create an instance of the barcode engine
BarcodeEngine engine = new BarcodeEngine();
//add read options for the sybologies you will recognize
QRBarcodeReadOptions qrReadOptions = new QRBarcodeReadOptions();
qrReadOptions.EnableDoublePass = true;
//barcode symbologies to detect
BarcodeSymbology[] symbologies = new BarcodeSymbology[] { BarcodeSymbology.QR, BarcodeSymbology.Datamatrix };
BarcodeReadOptions[] readOptions = { qrReadOptions };
// Read all the barcodes in this image
BarcodeData[] DetectedBarcodecs = engine.Reader.ReadBarcodes(image, LogicalRectangle.Empty, 0, symbologies, readOptions);
Console.WriteLine("Page: " + i + "\n" + DetectedBarcodecs.Length + " barcodes found");
//loop through detected barcode array and print out any barcode information needed
foreach (BarcodeData data in DetectedBarcodecs)
{
if (data == null)
{
Console.WriteLine("No Barcodes found");
}
else
{
Console.WriteLine("Barcode Sybmology: " + data.Symbology + "\nBounds: " + data.Bounds + "\n");
}
}
}
}
}
}
Edited by user Thursday, January 19, 2017 9:38:44 AM(UTC)
| Reason: spelling fixed
Roberto Rodriguez
Developer Support Engineer
LEAD Technologies, Inc.
![LEAD Logo LEAD Logo](https://www.leadtools.com/images/new-site-images/leadtools-logo-header.png)
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.