Skip to main content

Exception while spliting images into pages and writing it to file

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
3 replies [Last post]
tabs
Offline
Joined: 2011-07-04

Hi,

I'm facing below exception and tried to find out solution but didn't get much from google.

Exception while spliting images into pages and writing it to file




Caused by: java.lang.Error: Invalid code encountered while decoding 2D group 4 compressed data.
at com.sun.media.jai.codecimpl.TIFFFaxDecoder.decodeT6(TIFFFaxDecoder.java:1027)
at com.sun.media.jai.codecimpl.TIFFImage.getTile(TIFFImage.java:1067)
at com.sun.media.jai.codecimpl.SimpleRenderedImage.getData(SimpleRenderedImage.java:462)
at com.sun.media.jai.codecimpl.SimpleRenderedImage.getData(SimpleRenderedImage.java:422)
at com.sun.media.jai.codec.ImageDecoderImpl.decodeAsRaster(ImageDecoderImpl.java:138)

Code:fileData is byte data.

ByteArraySeekableStream ss = new ByteArraySeekableStream(fileData)

ImageDecoder dec = ImageCodec.createImageDecoder("tiff", ss, null);

int count = dec.getNumPages();

TIFFEncodeParam param = new TIFFEncodeParam();

param.setCompression(TIFFEncodeParam.COMPRESSION_GROUP4);

param.setLittleEndian(false);

RenderedImage page = dec.decodeAsRenderedImage(pageNumber);

File file = new File("c://image1.tiff");

ImageIO.write(page,"tiff",file); // Here on this line it is throwing exception

Jars:

jai-core-1.1.3.jar

jai-code-1.1.3.jar

jai-imageio-1.1.jar

java 6

It would be helpful if some one has any idea, please share.

Thanks.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
imagero
Offline
Joined: 2003-11-18

charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Mailer: Microsoft Office Outlook 12.0
Thread-Index: Acw6OT7qYXzg86qUS4ap2DcJSjb41gAANF8g
Content-Language: de

Hi,

It is much better if you split TIFF image without decoding it.

Andrey

tabs
Offline
Joined: 2011-07-04

Thanks for help..

Without decoding how will get the pages? Can you pls provide example....

Andrey Kuznetso...
Offline
Joined: 2011-07-06

charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Mailer: Microsoft Office Outlook 12.0
Thread-Index: Acw6wSwbP5vfjWKESL20GdB5+sGFtAAELZaA
Content-Language: de

This is not trivial, I implemented it in Imagero.=20
Imagero is commercial library however.=20
If you need it for private or nonprofit use you may get Imagero license =
for free.
Or you may read TIFF documentation and implement it by yourself (take at =
least 3 to 6 months time for that)...

Andrey