I originally wanted to know which image formats are supported by Swing, platform-independently. Swing is my preferred toolkit, and I am trying to research the decision of which image format to use in my hobby work. Once I know which formats are inherently supported, I will decide whether it is simpler to work with one of them or if it is simpler to find and work with appropriately-licensed third-party library. However, I've hit a snag and I want help to sort out where I went wrong.
I've done some digging through the javax.imageio API and I have unsuccessfully attempted to determine what formats are supported on my PC, by doing the following:
package iiortester;
import javax.imageio.spi.IIORegistry;
import javax.imageio.spi.ImageReaderSpi;
public class IIORTester {
public static void main(String[] args) {
IIORegistry iioRegistry = IIORegistry.getDefaultInstance();
ImageReaderSpi imageReaderSpi =
iioRegistry.getServiceProviderByClass(ImageReaderSpi.class);
System.out.println(imageReaderSpi); // output is null
}
}
The default IIORegistry instance did report the category ImageReaderSpi when I made a call to ServiceRegistry.getCategories()
, but when I attempt to acquire the image reader service provider interface in the code above, I receive a null
reference. This is likely a hint that I'm not going about this the right way, and my plan to query ImageReaderWriterSpi.getFormatNames()
has been foiled. However, even if it was successful in reporting supported image formats, that would not tell me whether those formats are supported inherently in any JVM or whether they're supported because I am running a Windows 7 JVM.
Am I looking in the wrong place? Probably. Where should I have been looking? I don't know. Does the JVM even have built-in ImageIO service providers, or is this only for third-party library registration? Where in the Swing API can software look up supported image formats?