Java Swing How to - Get supported image types








Question

We would like to know how to get supported image types.

Answer

import javax.imageio.ImageIO;
/*w ww  . j  a va2  s.c o m*/
public class Main {

    public static void main(String[] args) throws Exception {
        String[] types = ImageIO.getReaderFileSuffixes();
        System.out.println("This JRE supports image types:");
        for (String type : types) {
            System.out.println("Type: " + type);
        }
    }
}

Output here/now

This JRE supports image types:
Type: bmp
Type: jpg
Type: wbmp
Type: jpeg
Type: png
Type: gif

The code above generates the following result.