Listing the Image Formats That Can Be Read and Written - Java 2D Graphics

Java examples for 2D Graphics:Image

Description

Listing the Image Formats That Can Be Read and Written

Demo Code


import java.util.HashSet;
import java.util.Set;

import javax.imageio.ImageIO;

public class Main {
  public static void main(String[] argv) {
    // Get list of unique supported read formats
    String[] formatNames = ImageIO.getReaderFormatNames();
    formatNames = unique(formatNames);/*w ww.  ja v a  2  s . c  o  m*/

    // Get list of unique supported write formats
    formatNames = ImageIO.getWriterFormatNames();
    formatNames = unique(formatNames);

    // Get list of unique MIME types that can be read
    formatNames = ImageIO.getReaderMIMETypes();
    formatNames = unique(formatNames);


    // Get list of unique MIME types that can be written
    formatNames = ImageIO.getWriterMIMETypes();
    formatNames = unique(formatNames);

  }
  public static String[] unique(String[] strings) {
    Set set = new HashSet();
    for (int i = 0; i < strings.length; i++) {
      String name = strings[i].toLowerCase();
      set.add(name);
    }
    return (String[]) set.toArray(new String[0]);
  }
}

Related Tutorials