This technical tip shows how to Read Barcode from Multi-page TIFF Images using Aspose.BarCode for Java. Please make sure to install JRE 1.5 or above to run and JDK 1.5 or above for development. Then Download Aspose.BarCode for Java and install it as well. Below is the sample code for recognizing barcodes with in a multi-page tiff image.

[Java]

import com.aspose.barcode.*;
import com.sun.media.jai.codec.ImageCodec;
import com.sun.media.jai.codec.ImageDecoder;
import com.sun.media.jai.codec.TIFFDecodeParam;

import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;



/**
* Read barcodes from multi-pages tiff image sample
* Integreted Sun's JAI (Java Advanced Imaging) Library to working with tiff files
* Details information about JAI: Java Media APIs
*/
public class TiffWithJAI {

public static void main(String[] args) throws Exception {
String fileName = "C:\\multi_page.tiff";
Iterator readers = javax.imageio.ImageIO.getImageReadersBySuffix("tif f");
if (readers.hasNext()) {
File fi = new File(fileName);
ImageInputStream iis = javax.imageio.ImageIO.createImageInputStream(fi);
TIFFDecodeParam param = null;
ImageDecoder dec = ImageCodec.createImageDecoder("tiff", fi, param);
//Get the page count of the tiff image
int pageCount = dec.getNumPages();
ImageReader _imageReader = (ImageReader) (readers.next());
if (_imageReader != null) {
_imageReader.setInput(iis, true);
//Feed each page to the BarCodeReader
for (int i = 0; i < pageCount; i++) {
BufferedImage _bufferedImage = _imageReader.read(i);
com.BarCodeReader reader = new BarCodeReader(_bufferedImage, BarCodeReadType.Datamatrix);
//Read the barcodes in a single page
while (reader.read())
{
System.out.println(reader.getCodeText());
}
}

}
}
}
}


More about Aspose.BarCode for Java

- Homepage of Aspose.BarCode for Java: Java Barcode Generator & Reader Library, Export Barcodes to Images

- Read more technical tips by Aspose.BarCode for Java: Aspose.BarCode for Java - Documentation

- Download Aspose.BarCode for Java: Aspose.BarCode for Java - Java Components - Files


Contact Information
Suite 119, 272 Victoria Avenue
Chatswood, NSW, 2067
Australia
File Format Components for .NET Java SSRS SharePoint JasperReports
sales@aspose.com
Phone: 888.277.6734
Fax: 866.810.9465l