Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

How to Read Barcode from Multi-page TIFF Images

 
Ranch Hand
Posts: 714
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

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

                        {

                            System.out.println(reader.getCodeText());

                        }

                }


            }

        }   

    }

}


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

Australia

Aspose - The .NET and Java component
publisher


sales@aspose.com


Phone: 888.277.6734

Fax: 866.810.94651

 
reply
    Bookmark Topic Watch Topic
  • New Topic