Programming Tutorials Browser Tutorials Articles Struts Tutorials Hibernate Tutorials

  Tutorial: Loading and Saving Images with the Image I/O Library

Loading and Saving Images with the image I/O Library J2SE 1.4, the javax.imageio package is the primary package for the Java Image I/O API. As its name implies, this package helps you read and write image files. You might wonder what\'s so important abo

Tutorial Details:

the Image I/O libraries is what formats are supported? With Sun\'s reference implementation, you get a specific set. However, the API is flexible enough so that you can install your own formats by extending the necessary classes in the javax.imageio.spi library. For the moment, let\'s put that aspect of the library aside. To discover the installed set of readers and writers, you simply ask the ImageIO class through its getReaderFormatNames() and getWriterFormatNames() methods (or getReaderMIMETypes() and getWriterMIMETypes() if you want to work directly with MIME types). import javax.imageio.*;

public class GetList {
public static void main(String args[]) {
String readerNames[] =
ImageIO.getReaderFormatNames();
printlist(readerNames, \"Reader names:\");
String readerMimes[] =
ImageIO.getReaderMIMETypes();
printlist(readerMimes, \"Reader MIME types:\");
String writerNames[] =
ImageIO.getWriterFormatNames();
printlist(writerNames, \"Writer names:\");
String writerMimes[] =
ImageIO.getWriterMIMETypes();
printlist(writerMimes, \"Writer MIME types:\");
}
private static void printlist(String names[],
String title) {
System.out.println(title);
for (int i=0, n=names.length; i System.out.println(\"\\t\" + names[i]);
}
}
}

If you run the GetList program with Sun\'s reference implementation (and no custom providers installed), you should see the following output:

Reader names:
jpeg
gif
JPG
png
jpg
JPEG
Reader MIME types:
image/png
image/jpeg
image/x-png
image/gif
Writer names:
jpeg
JPG
png
jpg
PNG
JPEG
Writer MIME types:
image/png
image/jpeg

Basically, you get support for reading GIF, JPEG, and PNG formatted images, and for writing JPEG and PNGs. There is no GIF writer provided.

As you work with the Image I/O libraries, you might notice that almost all the work is requested through the static methods of the ImageIO class. For basic usage, these static methods are all you need. For example, to read an image, you pass the location to one of the following read methods of ImageIO:

read(File input)
read(ImageInputStream stream)
read(InputStream input)
read(URL input)


 

Read Tutorial at: Click here to view the tutorial

Rate Tutorial:
Loading and Saving Images with the Image I/O Library

View Tutorial:
Loading and Saving Images with the Image I/O Library

Related Tutorials:

Saving and retrieving objects with Java
Saving and retrieving objects with Java
 
Image processing with Java 2D - JavaWorld - September 1998
Image processing with Java 2D - JavaWorld - September 1998
 
Java Tip 74: Build dynamically extensible frameworks - JavaWorld
Java Tip 74: Build dynamically extensible frameworks - JavaWorld
 
How to drag and drop with Java 2, Part 2 - JavaWorld August 1999
How to drag and drop with Java 2, Part 2 - JavaWorld August 1999
 
A promise of easier embedded-systems networking - JavaWorld November 1999
A promise of easier embedded-systems networking - JavaWorld November 1999
 
Create dynamic images in Java servlets - JavaWorld May 2000
Create dynamic images in Java servlets - JavaWorld May 2000
 
Dynamic user interface is only skin deep - JavaWorld May 2000
Dynamic user interface is only skin deep - JavaWorld May 2000
 
Become a programming Picasso with JHotDraw - JavaWorld February 2001
Become a programming Picasso with JHotDraw - JavaWorld February 2001
 
Printing in Java, Part 5 - JavaWorld March 2001
Printing in Java, Part 5 - JavaWorld March 2001
 
Cut down on logging errors with Jylog
Cut down on logging errors with Jylog
 
Take control with the Proxy design pattern
Take control with the Proxy design pattern
 
Bridge the gap between Java and Twain
Bridge the gap between Java and Twain
 
Chart a new course with JFreeChart
Chart a new course with JFreeChart
 
Filtering and Transforming Digital Images
Filtering and Transforming Digital Images In this Issue Welcome to the Core Java Technologies Tech Tips for April 7, 2004. Here you\'ll get tips on using core Java technologies and APIs, such as those in Java 2 Platform, Standard Edition (J2SE).
 
JSANE - Image Acquisition from Digital Cameras and Scanners
JSANE - Image Acquisition from Digital Cameras and Scanners Image Acquisition from Digital Cameras and Scanners with Java on Mac/Linux/Solaris/Unix/BSD, etc. SANE is the de facto standard to access scanners/cameras on AIX, BeOS, Darwin, FreeBSD, HP-
 
G (2D graphic library)
G is a generic graphics library built on top of Java 2D in order to make scene graph oriented 2D graphics available to client applications in a high level, easy to use way
 
HeapAnalyzer
What is HeapAnalyzer? HeapAnalyzer allows the finding of a possible JavaTM heap leak area through its heuristic search engine and analysis of the Java heap dump in Java applications. Java heap areas define objects, arrays, and classes.
 
Java Tech: Acquire Images with TWAIN and SANE, Part 1
Scanners, digital cameras, and other image-acquisition devices are part of the computing landscape. Despite their ubiquity, however, Java does not provide a standard API for interacting with these devices. And yet there certainly is a desire to have a sta
 
Using image in WML We can use the
Using image in WML We can use the Tutorial Using image in WML In this lesson we will write application that images. We can use the tag to display the image in our document. The image appears wherever tag is placed within the text.
 
VolatileBufferedToolkitImage Strategies
Ever wondered what kind of image to use in your application? Or what method to use in creating it? This article attempts to address this challenging topic.
 
Site navigation
 

 

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2006. All rights reserved.