Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make ImageIO support more formats

I am currently writing an image converter in Java using ImageIO. Unfortunately ImageIO does not support many formats. The javadoc says it can be extended with plugins but I can't find any. I have tried JAI (Java Advanced Imaging) but it seems to be a whole new library not only a plugin.

Do you have an idea how to make ImageIO support more formats?

like image 906
Markus Avatar asked Dec 20 '22 04:12

Markus


2 Answers

ImageIO uses a service provider API, and most plugins comes as a jar you simply put in classpath. ImageIO will pick them up automatically.

It's probably easier to give good answers, if you list the formats you need support for.

As mentioned, JAI adds some format support (note that you need the jai-imageio.jar, not the complete JAI package). Warning: Many of them requires native library support to be of much use, and the project seems to be left in limbo by Oracle.

I've written a couple of plugins (mostly readers), that will extend the number of formats supported (most notably TIFF, PSD (Photoshop) and PICT, as well as extended JPEG support).

jrawio is another good example (as mentioned in the comments), if you need camera RAW file support.

Googling brings up quite a few more. As I said, it all depends on what formats you need.

like image 122
Harald K Avatar answered Jan 03 '23 22:01

Harald K


javax.imageio support for formats works on the basis of a Service Provider Interface. An SPI is just a special Jar that:

  1. Provides a class for decoding/encoding an image.
  2. Puts a file in a certain place in the Jar to identify the class that does the encoding & decoding.

AFAIU, JAI provides SPIs for other formats not supported by 'plain' ImageIO.

For more details, see JavaTM Image I/O Technology.

like image 31
Andrew Thompson Avatar answered Jan 03 '23 22:01

Andrew Thompson