且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用 ImageIO 将 JPEG2000 转换为 PNG

更新时间:2023-01-18 14:56:24

ImageIO 内置以下格式:BMP、GIF、JPEG、PNG、WBMP(来源:API 文档).如果您尝试读取不同格式的图像,ImageIO.read(...) 方法将简单地返回 null,这就是您获得 的原因IllegalArgumentException: im == null 稍后在您的方法中.

ImageIO comes with the following formats built in: BMP, GIF, JPEG, PNG, WBMP (source: the API documentation). If you try to read an image in a different format, the ImageIO.read(...) methods will simply return null, which is why you get the IllegalArgumentException: im == null later in your method.

但是,ImageIO 还使用插件机制(服务提供者接口,或 SPI),以允许安装额外的或第三方插件.

However, ImageIO also uses a plugin mechanism (service provider interface, or SPI), to allow for extra or third-party plugins to be installed.

为了能够读取 JPEG2000 或 TIFF,您需要这样的插件.

To be able to read JPEG2000 or TIFF, you need such a plugin.

  • 对于 JPEG2000,***的选择可能是 JAI.JAI 还有一个 TIFF 插件.JAI 由 Sun(现为 Oracle)开发,但遗憾的是,多年来一直没有更新和错误修复.

  • For JPEG2000 the best option is probably JAI. JAI also has a TIFF plugin. JAI was developed by Sun (now Oracle), but unfortunately, there hasn't been updates and bug fixes for years.

还有用于 OpenJPEG 的 Java 绑定,其中应包含用于 JPEG2000 的 ImageIO 插件.

There's also Java bindings for OpenJPEG that should contain an ImageIO plugin for JPEG2000.

对于 TIFF,您还可以使用我的 TwelveMonkeys ImageIO TIFF 插件.TwelveMonkeys 目前没有 JPEG2000 插件,所以它可能对您不太有用.

For TIFF you can also use my TwelveMonkeys ImageIO TIFF plugin. TwelveMonkeys does not currently have a JPEG2000 plugin, so it might be less useful for you.

(此列表并不详尽,Google 可能会帮助您找到更多信息 :-) )

(This list is not exhaustive, Google might help you find more :-) )

PS:从 Java 9 (JEP-262) 及更高版本开始,还内置了 TIFF 格式支持.

PS: From Java 9 (JEP-262) and later, TIFF format support is also built in.