Background
The Atalasoft BarcodeReader can sometimes get "confused" by multiple barcodes which are a bit too close to each other... this can result in missed barcodes on a page even though the barcode images are completely valid and should have read.
Here are two sample methods (meant to be used together) to perform an iterative read:
// The DotImage barcode reading engine may get confused by multiple barcodes in too-close proximity
// to each other... this method will use an iterative process to try and read what it can, then
// hide the codes it found and re-read to see if more barcodes can be found...
//
// It will continue looping until no new barcodes are found.
private BarCode[] ReadAllBarcodesFromImage(AtalaImage image, ReadOpts options, bool useThresholding)
{
// Doing this ensures we are not modifying the image object that was passed in
AtalaImage imgCopy = (AtalaImage)image.Clone();
List<BarCode> allCodes = new List<BarCode>();
// the first pass uses an unaltered image so just do that first
BarCode[] codes = PerformRead(imgCopy, options, useThresholding);
// Now, we will set up the Canvas which we will "white out" found barcodes from the previous run
Canvas c = new Canvas(imgCopy);
// iterate the results, doing the whilteout.. then try re-reading to see if we get more results
while (codes != null && codes.Length > 0)
{
foreach (var bc in codes)
{
// Ok, we have a barcode... add it to the return list
allCodes.Add(bc);
// this code will write out a white rectangle over the location of the found barcode in the image supplied...
// that will allow the engine to have a new, fresh view of the page where the already found codes are not present
c.DrawRectangle(bc.BoundingRect, new SolidFill(Color.White));
}
// once again, we do a read.. if we end up not finding results we're done
// if we find any new barcodes, we'll repeat the process, adding barcodes to the already found ones
codes = PerformRead(imgCopy, options, useThresholding);
}
// this is no longer needed, so clean up after ourselves
imgCopy.Dispose();
// finally, return the results as an array
return allCodes.ToArray();
}
// We need this method because even though we're updating the image directly the engine needs a new, updated copy
private BarCode[] PerformRead(AtalaImage image, ReadOpts options, bool useThresholding)
{
BarCode[] results = null;
using (BarCodeReader reader = new BarCodeReader(image, useThresholding))
{
results = reader.ReadBars(options);
}
return results;
}
Original Article
Q10422 - FIX: BarcodeReader Misses One or More Barcodes on an Image Containing Multiple Adjacent Barcodes
Last Update
2026-11-04 - TD - (Code fencing and headings)