Read Barcodes in a Specific Order
Contents
[
Hide
]
When an image has several barcodes users might want to read them in a particular order. This article shows how to do so using Aspose.BarCode for Java.
The code examples given below demonstrate how to read barcodes in a specific order.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FoundBarCodes { | |
String CodeText; | |
BarCodeRegionParameters BarCodeRegion; | |
public FoundBarCodes(String cText, BarCodeRegionParameters barCodeRegionParameters) { | |
this.CodeText = cText; | |
this.BarCodeRegion = barCodeRegionParameters; | |
} | |
public String getCodeText() { | |
return CodeText; | |
} | |
public com.aspose.barcode.barcoderecognition.BarCodeRegionParameters getRegion() { | |
return BarCodeRegion; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getDataDir(ReadAndSortBarcodesInSpecificOrder.class) + "TechnicalArticles/"; | |
String path = dataDir + "barcode.png"; | |
List<FoundBarCodes> found = new ArrayList<FoundBarCodes>(); | |
BarCodeReader reader = new BarCodeReader(path, DecodeType.CODE_128); | |
for (BarCodeResult result : reader.readBarCodes()) | |
{ | |
found.add(new FoundBarCodes(result.getCodeText(), result.getRegion())); | |
} | |
Comparator<FoundBarCodes> foundComparator = new Comparator<FoundBarCodes>() { | |
@Override | |
public int compare(FoundBarCodes e1, FoundBarCodes e2) { | |
return e1.getCodeText().compareTo(e2.getCodeText()); | |
} | |
}; | |
found.sort(foundComparator); | |
int i = 1; | |
for (FoundBarCodes barcode : found) { | |
Point[] point = barcode.BarCodeRegion.getPoints(); | |
System.out.println("Codetext ( " + i + " ): " + barcode.CodeText); | |
System.out.println("Top left coordinates: X = " + point[0].getX() + ", Y = " + point[0].getY()); | |
System.out.println("Bottom left coordinates: X = " + point[1].getX() + ", Y = " + point[1].getY()); | |
System.out.println("Bottom right coordinates: X = " + point[2].getX() + ", Y = " + point[2].getY()); | |
System.out.println("Top right coordinates: X = " + point[3].getX() + ", Y = " + point[3].getY()); | |
System.out.println(); | |
i++; | |
} |