开发者

Java JAI JPEG image encode RuntimeException

I'm trying to build an application that encodes and resize images off any type of image and store it as a JPEG.

I use this kind of weird jpeg and use for testing.

For some reason JAI cannot render this image as a JPEG. I use the following code:

private SeekableStream seekableStream;
...
public RenderedOp builRenderedOp(byte[] bytes) {
    seekableStream = SeekableStream.wrapInputStream(new ByteArrayInputStream(bytes),true);
    RenderedOp img = JAI.create("stream", seekableStream);
    return img ;
}
...
public void writeImageToJPEG(OutputStream out,RenderedOp image,float quality) throws IOException {
    JPEGEncodeParam encodeParam = new JPEGEncodeParam();
    encodeParam.setQuality(quality);

    ImageEncoder encoder = ImageCodec.createImageEncoder("JPEG", out, encodeParam);

    encoder.encode(image);
}

on encoder.encode(image) a RuntimeException is thrown.

java.lan开发者_JAVA百科g.RuntimeException: - Unable to render RenderedOp for this operation.
    at javax.media.jai.RenderedOp.createInstance(RenderedOp.java:838)
    at javax.media.jai.RenderedOp.createRendering(RenderedOp.java:878)
    at javax.media.jai.RenderedOp.getWidth(RenderedOp.java:2190)
....

Any suggestions?


A RuntimeException is a wrapper for exceptions. Try using the getCause to print the stack trace of the actaul exception being thrown:

http://java.sun.com/j2se/1.4.2/docs/api/java/lang/RuntimeException.html

It's also possible this JPEG file isn't supported by the library being used, such as libjpeg or something related to JPEG 2000 or something out-of-spec.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜