jQuery in Action, 3rd edition
The moose likes Blatant Advertising and the fly likes How to Read Barcode from Multi-page TIFF Images Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Other » Blatant Advertising
Bookmark "How to Read Barcode from Multi-page TIFF Images" Watch "How to Read Barcode from Multi-page TIFF Images" New topic

How to Read Barcode from Multi-page TIFF Images

sherazam khan
Ranch Hand

Joined: Mar 10, 2010
Posts: 378
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, install it as well.  Below is the sample code for recognizing barcodes with in a multi-page tiff image.


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: http://java.sun.com/javase/technologies/desktop/media/


public class TiffWithJAI {

    public static void main(String[] args) throws Exception {

                String fileName = "C:\\multi_page.tiff";

        Iterator readers = javax.imageio.ImageIO.getImageReadersBySuffix("tiff");

        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())









More about Aspose.BarCode for Java

- Homepage of Aspose.BarCode for Java

- Read more Technical Tips by Aspose.BarCode

- Download of Aspose.BarCode for Java

Contact Information

Aspose Pty Ltd

Suite 163, 79 Longueville Road

Lane Cove, NSW, 2066


Aspose - The .NET and Java component


Phone: 888.277.6734

Fax: 866.810.94651

I agree. Here's the link: http://aspose.com/file-tools
subject: How to Read Barcode from Multi-page TIFF Images
jQuery in Action, 3rd edition