• Menu
  • Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

JavaBeat

Java Tutorial Blog

  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)
  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)

How To Get Supported Image Formats Using Java

April 21, 2014 //  by Krishna Srinivasan//  Leave a Comment

This example is for how to list read/write image formats in the Java applications. If you are working with the image processing applications, it is necessary to know the supported formats to inform the user. Lets look at the example on how to list read/write image formats. SupportedImageFormatsExample.java

package javabeat.net.core;

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

import javax.imageio.ImageIO;

/**
 * Supported Types Example
 *
 * @author Krishna
 *
 */
public class SupportedImageFormatsExample {
	public static void main(String[] args) {
		Set setOfSupportedTypes = new HashSet();

		//Get list of all registered readers
		String[] formatNamesArray = ImageIO.getReaderFormatNames();

		for (int i = 0; i < formatNamesArray.length; i++) {
			setOfSupportedTypes.add(formatNamesArray[i].toLowerCase());
		}

		System.out.println("Read Formats Supported : " + setOfSupportedTypes);
		setOfSupportedTypes.clear();

		//Get list of all registered writers
		formatNamesArray = ImageIO.getWriterFormatNames();

		for (int i = 0; i < formatNamesArray.length; i++) {
			setOfSupportedTypes.add(formatNamesArray[i].toLowerCase());
		}
		System.out.println("Write Formats Supported : " + setOfSupportedTypes);
		setOfSupportedTypes.clear();

		//Get list of all MIME types registered readers
		formatNamesArray = ImageIO.getReaderMIMETypes();

		for (int i = 0; i < formatNamesArray.length; i++) {
			setOfSupportedTypes.add(formatNamesArray[i].toLowerCase());
		}
		System.out.println("Supported read MIME types: " + setOfSupportedTypes);
		setOfSupportedTypes.clear();

		//Get list of all MIME types registered writers
		formatNamesArray = ImageIO.getWriterMIMETypes();

		for (int i = 0; i < formatNamesArray.length; i++) {
			setOfSupportedTypes.add(formatNamesArray[i].toLowerCase());
		}
		System.out.println("Supported write MIME types: " + setOfSupportedTypes);
	}
}

Output…

Read Formats Supported : [jpg, bmp, jpeg, wbmp, png, gif]
Write Formats Supported : [bmp, jpg, wbmp, jpeg, png, gif]
Supported read MIME types: [image/jpeg, image/png, image/x-png, image/vnd.wap.wbmp, image/bmp, image/gif]
Supported write MIME types: [image/png, image/jpeg, image/x-png, image/vnd.wap.wbmp, image/bmp, image/gif]

Category: JavaTag: Java ImageIO

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Previous Post: «java How To Compress Image Using Java
Next Post: Java ScriptEngine Example »

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Follow Us

  • Facebook
  • Pinterest

FEATURED TUTORIALS

New Features in Spring Boot 1.4

Difference Between @RequestParam and @PathVariable in Spring MVC

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Introductiion to Jakarta Struts

What’s new in Struts 2.0? – Struts 2.0 Framework

JavaBeat

Copyright © by JavaBeat · All rights reserved
Privacy Policy | Contact