Below is the code I borrowed/wrote to read in multi page TIFF images and detect their barcodes, if any. Attached is a generic file I scanned in as a TIFF image. It has no barcode on, which is on purpose.
public class ReadBarcodesFromMultipageTiffs {
public static void main(String… args) {
try {
new ReadBarcodesFromMultipageTiffs().read();
} catch (IOException e) {
e.printStackTrace();
}
}
private void read() throws IOException {
initLicense();
String filename = “c:\barcode\1116.tif”;
Iterator readers = ImageIO.getImageReadersBySuffix(“tiff”);
if(readers.hasNext()) {
File fileToRead = new File(filename);
ImageInputStream imageInputStream = ImageIO.createImageInputStream(fileToRead);
TIFFDecodeParam tiffDecodeParam = null;
ImageDecoder imageDecoder = ImageCodec.createImageDecoder(“tiff”, fileToRead, tiffDecodeParam);
//Get the page count of the tiff image
int pageCount = imageDecoder.getNumPages();
ImageReader imageReader = (ImageReader) (readers.next());
imageReader.setInput(imageInputStream, true);
//Feed each page to the BarCodeReader
for(int i = 0; i < pageCount; i++) {
BufferedImage bufferedImage = imageReader.read(i);
BarCodeReader barCodeReader = new BarCodeReader(bufferedImage);
while(barCodeReader.read()) {
System.out.println("Text: " + barCodeReader.getCodeText());
System.out.println("Type: " + barCodeReader.getReadType().toString());
Point[] points = barCodeReader.getRegion().Points();
for(Point point : points) {
System.out.println("point: " + point);
}
}
}
}
}
private void initLicense() {
License license = new License();
license.setLicense(“resources\Aspose.Barcode.lic”);
}
}
But this is the output I get:
Text: 5243
Type: DataMatrix
point: java.awt.Point[x=1520,y=396]
point: java.awt.Point[x=1583,y=396]
point: java.awt.Point[x=1583,y=458]
point: java.awt.Point[x=1520,y=458]
So it appears that it thinks the “M” in “NAME” is a DataMatrix barcode, which to me shouldn’t be the case. Is this a bug of a freak coincidence that an M is equal to 5243 for a DataMatrix?
Thank you,
Todd
Hi Todd,
Thank you for inquiry.
Which version of Aspose.BarCode for Java are you using?
Could you please also try the attached sample to read this tif document. No barcode was found when I used the attached sample at my end.
One more thing, I see that you are calling initLicense() in the read() method. Please move it to main() or init() method, so that the license is set only once per program execution.