HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML

"The Java Image Management Interface"
Volume: 3 Issue: 11, p. 46


Listing 1.
Basic image conversion with JIMI 

import com.activated.jimi.*; 
import java.awt.Image; 

public class JimiIsReallyEasy { 
 public static void main(String[] args) 
  throws JimiException { 
  Image image = Jimi.getImage("myImage.PSD"); 
  Jimi.putImage(image, "myImage.PNG"); 

Listing 2.
Reading and writing multiple image files 

import com.activated.jimi.*; 

import java.awt.*; 
import java.util.*; 

 * A simple example program for reversing the 
 * order of frames in a multi-frame image. 
public class ImageSeriesReverser 
 public static void main(String[] args) 
  // print usage if wrong arguments are given 
  if (args.length != 2) { 
   System.err.println("Requires args: <src> <dest>"); 

  // vector to store loaded images in 
  Vector images = new Vector(); 

  // read the images 
  try { 
   // create a JimiReader to read the image 
   // series from 
   JimiReader jr = Jimi.createJimiReader(args[0]); 
   // enumerate the images in the series 
   Enumeration e = jr.getImageEnumeration(); 
   // insert them into the vector in reverse 
   while (e.hasMoreElements()) { 
    Image i = (Image)e.nextElement(); 
    images.insertElementAt(e, 0); 
  // catch exception if the source file 
  // is malformed 
  catch (JimiException e) { 
   System.err.println("Error: " + e); 
  // write the images back in reverse 
  try { 
   // create a JimiWriter for the output file 
   JimiWriter jw = Jimi.createJimiWriter(args[1]); 
   // pull the images out of the vector and 
   // into an array 
   Image[] series = new Image[images.size()]; 
   // set the image array as the source for 
   // the JimiWriter 
   // write the images! 
  // catch exception if the output file 
  // can't be written to 
  catch (JimiException e) { 
   System.err.println("Error: " + e); 
  // finished! 

Listing 3. 
Image Processing example method 

public JimiBufferedRasterImage flipImage(JimiRasterImage source) 
 throws ImageAccessException 
 // the dimensions of the source image, which 
 // are used to create a same-sized target image 
 int width = source.getWidth(); 
 int height = source.getHeight(); 
 // create an empty target image to populate 
 // with flipped data 
 JimiBufferedRasterImage target = 
 // a small buffer for pixel data to copy-between 
 int[] rowBuffer = new int[width]; 
 // the index of the last row of the image 
 int lastRow = height - 1; 
 // loop through, copying each row from source to destination 
 for (int row = 0; row < height; row++) { 
  // get the source row 
  source.getRowRGB(row, rowBuffer, 0); 
  // copy it into the destination image at the 
  // opposite location 

  target.setRowRGB(lastRow-row, rowBuffer, 0); 
 // all finished, the target image is now fully populated 
 return target; 


All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.