Java JAI JPEG 图像编码 RuntimeException
我正在尝试构建一个应用程序,对任何类型的图像进行编码和调整图像大小,并将其存储为 JPEG。
我使用这个 有点奇怪的 jpeg 并使用用于测试。
由于某种原因,JAI 无法将此图像渲染为 JPEG。我使用以下代码:
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);
}
在 encoder.encode(image)
上抛出 RuntimeException
。
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)
....
有什么建议吗?
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.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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
RuntimeException
是异常的包装器。尝试使用 getCause 打印抛出的 actaul 异常的堆栈跟踪:http://java.sun.com/j2se/1.4.2/docs/api/java/lang/RuntimeException.html
这个 JPEG 文件也是可能的所使用的库不支持,例如
libjpeg
或与 JPEG 2000 相关的内容或不符合规范的内容。A
RuntimeException
is a wrapper for exceptions. Try using thegetCause
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.