JavaBeat

  • Home
  • 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)
  • Privacy

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

[code lang=”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);
}
}

[/code]

Output…

[code]
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]
[/code]

Filed Under: Java Tagged With: 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.

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.

Follow Us

  • Facebook
  • Pinterest

As a participant in the Amazon Services LLC Associates Program, this site may earn from qualifying purchases. We may also earn commissions on purchases from other retail websites.

JavaBeat

FEATURED TUTORIALS

Answered: Using Java to Convert Int to String

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Copyright © by JavaBeat · All rights reserved