Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Wednesday, May 12, 2021 10:28:12 AM(UTC)

Bobby L  
Bobby L

Groups: Registered
Posts: 19

Thanks: 1 times

I am trying to write a clean standalone barcode reader application based off the C# Barcode Demo application (BarcodeMainDemo)

When I load my sample image into the BarcodeMainDemo application and limit BarcodeSymbologies to BarcodeSymbology.Code3Of9, it works.

However, when I try the same thing in my standalone application it fails to find any barcodes. The code compiles and runs, it just doesn't find any barcodes.

My complete code is below. Any help is appreciated
(Note: I set the bounds to (0,0,0,0) after I noticed via debugging that was the value in the BarcodeMainDemo )

namespace StandaloneBarcodeDemo
{
public partial class Form1 : Form
{

private BarcodeEngine _barcodeEngine;
private BarcodeSymbology[] _symbologies = new BarcodeSymbology[1];
private RasterImage _rasterImage;
private RasterCodecs codecs;
private LeadRect _bounds;

public Form1()
{
InitializeComponent();

string developerLicenseFilePath = @"C:\LEADTOOLS21\Support\Common\License\LEADTOOLS.LIC";
string contentsOfDeveloperKeyFile = System.IO.File.ReadAllText(@"C:\LEADTOOLS21\Support\Common\License\LEADTOOLS.LIC.KEY");
if (developerLicenseFilePath != string.Empty && contentsOfDeveloperKeyFile != string.Empty)
RasterSupport.SetLicense(developerLicenseFilePath, contentsOfDeveloperKeyFile);

}

private void cmdProcess_Click(object sender, EventArgs e)
{
int pageCount = 0;
if (txtSourceImage.Text != "")
{
//initialize codecs engine
codecs = new RasterCodecs();
codecs.Options.Load.AllPages = true;

try
{
//load the image
_rasterImage = codecs.Load(txtSourceImage.Text);

//get the page count
pageCount = _rasterImage.PageCount;

//look for only 3of9 Barcodes
//_symbologies = new BarcodeSymbology[1];
_symbologies[0] = BarcodeSymbology.Code3Of9;

//set bounds
//_bounds = new LeadRect(0, 0, _rasterImage.Width, _rasterImage.Height);
_bounds = new LeadRect(0, 0, 0, 0);

//setup the engine
_barcodeEngine = new BarcodeEngine();

// Ignore errors in case there are corrupted ones on the image.
_barcodeEngine.Reader.ErrorMode = BarcodeReaderErrorMode.IgnoreAll;

//start at the first page
_rasterImage.Page = 1;

BarcodeData[] barcodes = _barcodeEngine.Reader.ReadBarcodes(_rasterImage, _bounds, 0, _symbologies);
//_barcodeEngine.Reader.ReadBarcodes(_rasterImage, _bounds, 0, _symbologies, null);

//add barcodes to listbox
foreach (BarcodeData barcode in barcodes)
{
lstBarcodeValues.Items.Add(barcode.Value.ToString());
}
}
catch (Exception ex)
{
MessageBox.Show("Unexpected error:" + ex.Message + ":" + ex.InnerException);
}
}
}
}
}
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

#2 Posted : Wednesday, May 12, 2021 12:48:51 PM(UTC)

Nick  
Nick

Groups: Registered, Tech Support, Administrators
Posts: 163

Was thanked: 9 time(s) in 9 post(s)

Note the LEADTOOLS Barcode Demo makes some modifications to the RasterCodecs object to load the input file at a higher resolution than the default.
https://www.leadtools.co...s-rasterizedocument.html

Could you modify your code to include this as well?

Code:

         codecs = new RasterCodecs();
         codecs.Options.RasterizeDocument.Load.XResolution = 300;
         codecs.Options.RasterizeDocument.Load.YResolution = 300;


Depending on the format you're working with, this may resolve the issue. If the issue persists, I may need to examine the file you're working with locally.
Nick Crook
Developer Support Engineer
LEAD Technologies, Inc.
LEAD Logo
 
#3 Posted : Wednesday, May 12, 2021 1:02:46 PM(UTC)

Bobby L  
Bobby L

Groups: Registered
Posts: 19

Thanks: 1 times

I added the two lines above but it doesn't make a difference. IN fact I set a breakpoint after the codecs.Load() line to examine the rasterimages object and both the XRESOLUTION and YRESOLUTION are both at 200, despite the codecs.Options.RasterizeDocument.Load.Resolution settings.

Updated code snippet below

(Note I changed from .codecs.Load(txtSourceImage.Text) to codecs.Load(txtSourceImage.Text, 0, CodecsLoadByteOrder.BgrOrGray, 1, info.TotalPages) based on the code I saw in the demo)

codecs = new RasterCodecs();
codecs.Options.RasterizeDocument.Load.XResolution = 300;
codecs.Options.RasterizeDocument.Load.YResolution = 300;
codecs.Options.Load.AllPages = true;

try
{
//load the image
//_rasterImage = codecs.Load(txtSourceImage.Text);
CodecsImageInfo info = codecs.GetInformation(txtSourceImage.Text, true);
//_rasterImage = codecs.Load(txtSourceImage.Text);
_rasterImage = codecs.Load(txtSourceImage.Text, 0, CodecsLoadByteOrder.BgrOrGray, 1, info.TotalPages);

//Note the X and Y resolution still comes up as 200 DPI despite the lines above
 
#4 Posted : Wednesday, May 12, 2021 2:23:56 PM(UTC)

Nick  
Nick

Groups: Registered, Tech Support, Administrators
Posts: 163

Was thanked: 9 time(s) in 9 post(s)

Could you upload your image so I can examine it in conjunction with your code? I've sent you upload instructions via email.
Nick Crook
Developer Support Engineer
LEAD Technologies, Inc.
LEAD Logo
 
#5 Posted : Wednesday, May 12, 2021 3:16:19 PM(UTC)

Bobby L  
Bobby L

Groups: Registered
Posts: 19

Thanks: 1 times

Sorry, I had to step away for an appointment. I just uploaded the image and a zipped up version of the project.
 
#6 Posted : Thursday, May 13, 2021 8:48:43 AM(UTC)

Bobby L  
Bobby L

Groups: Registered
Posts: 19

Thanks: 1 times

I should also note that I tried using the sample barcode images from the DEMO Barcode project (C:\LEADTOOLS21\Resources\Images) in my project and those barcodes do not get detected either.
 
#7 Posted : Thursday, May 13, 2021 1:18:30 PM(UTC)

Bobby L  
Bobby L

Groups: Registered
Posts: 19

Thanks: 1 times

Nick,

One more update. I added some code to the LeadTools BarCodeMainDemo.

In the DoReadBarcodes() function, I added the following code prior to the for loop. Basically it's a messagebox which will prompt the user to load an alternate image to have it's barcode read (Not this image is NOT displayed in the viewer). Interestingly enough, when using this approach, the barcode from the C:\\Temp\\15289_00001AZZZ_P001.TIF does get read, which makes me think there must be some setting on the _barcodeReader object itself that I am missing in my standalone program.

Let me know your thoughts while I keep investigating.

if ( MessageBox.Show("Forcibly load test image","Barcode Test", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
RasterCodecs codecs = new RasterCodecs();
string srcLocation = "C:\\Temp\\15289_00001AZZZ_P001.TIF";
CodecsImageInfo info = codecs.GetInformation(srcLocation, true);
//_rasterImage = codecs.Load(txtSourceImage.Text);
_rasterImage = codecs.Load(srcLocation, 0, CodecsLoadByteOrder.BgrOrGray, 1, info.TotalPages);
}
 
#8 Posted : Thursday, May 13, 2021 2:39:05 PM(UTC)

Nick  
Nick

Groups: Registered, Tech Support, Administrators
Posts: 163

Was thanked: 9 time(s) in 9 post(s)

I've examined the sample project as well as the image you submitted. This appears to stem from a missing DLL. The Leadtools.Barcode.OneD.dll library is necessary for reading and writing linear barcodes.
https://www.leadtools.co.../to/barcode-support.html

This library is loaded automatically by reflection if it's in the same folder. This means it isn't necessary to explicitly reference it in your application, but doing so typically copies it to the output folder.
Nick Crook
Developer Support Engineer
LEAD Technologies, Inc.
LEAD Logo
 
#9 Posted : Thursday, May 13, 2021 2:54:19 PM(UTC)

Bobby L  
Bobby L

Groups: Registered
Posts: 19

Thanks: 1 times

Thanks Nick, I'll try it out and let you know

 
#10 Posted : Thursday, May 13, 2021 3:05:47 PM(UTC)

Bobby L  
Bobby L

Groups: Registered
Posts: 19

Thanks: 1 times

Nick, thanks for the help. I tried a few barcodes and they all work.

I'll make a note of the Leadtools.Barcode.OneD.dll for my future projects.
 
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.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.202 seconds.