views:

282

answers:

1

Hi there,

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

The current url -> http://gn.vinea.es/inmo.nsf/vwimagen/2031225200800143/$File/f225200800143.JPG is a 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.lang.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: 

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.

Kristopher Ives
http://twitter.com/kristopherives/status/8323842474
Kristopher Ives
Thanks for the reply but the problem was concerned with an other subject. The code I presented is ok.
Norberto