Java JAI JPEG 图像编码 RuntimeException

发布于 2024-08-19 10:52:08 字数 1259 浏览 15 评论 0原文

我正在尝试构建一个应用程序,对任何类型的图像进行编码和调整图像大小,并将其存储为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

謸气贵蔟 2024-08-26 10:52:08

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 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文