author-avatar
7/19/2020 2:13:18 PM
Рейтинг: 0

JAI Tiff to JPEG convertion issue

i have an issue converting Tiff-Files to JPEGs with JAI. This is my Code: ByteArrayOutputStream baos = new ByteArrayOutputStream(); TIFFDecodeParam param = null; ImageDecoder dec = ImageCodec.createImageDecoder("tiff", new FileSeekableStream(inPath), param); RenderedImage op = dec.decodeAsRenderedImage(0); JPEGEncodeParam jpgparam = new JPEGEncodeParam(); jpgparam.setQuality(67); ImageEncoder en = ImageCodec.createImageEncoder("jpeg", baos, jpgparam); en.encode(op); Mostly this code works fine, but with some Images, i got the following error: java.lang.RuntimeException: Only 1, or 3-band byte data may be written. at com.sun.media.jai.codecimpl.JPEGImageEncoder.encode(JPEGImageEncoder.java:142) i have an issue converting Tiff-Files to JPEGs with JAI. This is my Code: ByteArrayOutputStream baos = new ByteArrayOutputStream(); TIFFDecodeParam param = null; ImageDecoder dec = ImageCodec.createImageDecoder("tiff", new FileSeekableStream(inPath), param); RenderedImage op = dec.decodeAsRenderedImage(0); JPEGEncodeParam jpgparam = new JPEGEncodeParam(); jpgparam.setQuality(67); ImageEncoder en = ImageCodec.createImageEncoder("jpeg", baos, jpgparam); en.encode(op); Mostly this code works fine, but with some Images, i got the following error: java.lang.RuntimeException: Only 1, or 3-band byte data may be written. at com.sun.media.jai.codecimpl.JPEGImageEncoder.encode(JPEGImageEncoder.java:142) I cant find any related Problems over here and i have no idea how to fix it. The Images who throw this error have a high Resolution (9000 x 7000 or more) and are mostly scans of old pictures. May someone can explain what this error-message means and how to fix it? Many thanks in advice!
Ответить

Ничего не найдено