从 .tiff 文件创建 BufferedImage

发布于 2024-11-04 17:37:45 字数 993 浏览 0 评论 0原文

我正在尝试从 .tiff 文件创建 BufferedImage(raw() 是 .tiff 图像的路径):

// read a buffered image from the disk
BufferedImage buff = ImageIO.read(new File(raw()));

最初 ImageIO.read 返回 null,但我读到我需要将 JAI ImageIO JAR 添加到您的类路径,我做到了。现在我收到以下错误:

Exception in thread "main" javax.imageio.IIOException: I/O error reading image metadata!
        at com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.readMetadata(TIFFImageReader.java:340)
        at com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.seekToImage(TIFFImageReader.java:310)
        at com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.prepareRead(TIFFImageReader.java:971)
        at com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.read(TIFFImageReader.java:1153)
        at javax.imageio.ImageIO.read(ImageIO.java:1422)
        at javax.imageio.ImageIO.read(ImageIO.java:1282)
        at core.Page.initGuesses(Page.java:101)
....

有谁知道可能是什么问题?我做错了什么吗?

谢谢!

I'm trying to created a BufferedImage from a .tiff file (raw() is the path of a .tiff image):

// read a buffered image from the disk
BufferedImage buff = ImageIO.read(new File(raw()));

Originally ImageIO.read was returning null but I read that I need to add the JAI ImageIO JARs to your classpath, which I did. Now I'm getting the following error:

Exception in thread "main" javax.imageio.IIOException: I/O error reading image metadata!
        at com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.readMetadata(TIFFImageReader.java:340)
        at com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.seekToImage(TIFFImageReader.java:310)
        at com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.prepareRead(TIFFImageReader.java:971)
        at com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.read(TIFFImageReader.java:1153)
        at javax.imageio.ImageIO.read(ImageIO.java:1422)
        at javax.imageio.ImageIO.read(ImageIO.java:1282)
        at core.Page.initGuesses(Page.java:101)
....

Does anyone know what could be the problem? Am I doing something incorrectly?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

指尖上的星空 2024-11-11 17:37:45

我也面临着同样的问题。我试图从 tiff byte[] 获取 BufferedImage 但结果为 null。

我注释了 Tomcat 的 server.xml 文件中与 JreMemoryLeaks 相关的一行。
只需评论这一行:

Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"

这个解决方案对我有用。

I was also facing same problem. I was trying to get BufferedImage from tiff byte[] but was getting null as result.

I have commented one line from Tomcat's server.xml file which is related to JreMemoryLeaks.
Just comment this line:

Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"

This solution worked for me.

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