edu.sdsc.mbt.image
Class ImageUtils

java.lang.Object
  extended byedu.sdsc.mbt.image.ImageUtils

public class ImageUtils
extends java.lang.Object

Provides AWT-based (pure Java) image manipulation methods for cropping, scaling, and padding images.

Author:
John L. Moreland

Constructor Summary
ImageUtils()
           
 
Method Summary
static java.awt.image.BufferedImage autoCropAndScale(java.awt.Image image, int outWidth, int outHeight)
          Find the edges of the input image using the upper left corner pixel color as the background color, automatically crop the image down to eliminate the excess background border, then scale the image (maintaining the correct aspect ratio of the input image) and then center the image with appropriate background padding of the specified output width and height.
static int[] findEdges(int[] pixels, int width, int height)
          Find the edges of the image by finding the min/max x,y coordinate where pixels are a different color than the upper left pixel.
static int getPixel(int[] pixels, int width, int x, int y)
          Return one pixel (as 4-byte, 24-bit, 8-bit-per-component, ARGB int) given the raw pixel array returned by the getPixels method.
static int[] getPixels(java.awt.Image image)
          Return the pixels (as 4-byte, 24-bit, 8-bit-per-component, ARGB ints).
static void main(java.lang.String[] args)
          Unit testing entry point.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ImageUtils

public ImageUtils()
Method Detail

autoCropAndScale

public static java.awt.image.BufferedImage autoCropAndScale(java.awt.Image image,
                                                            int outWidth,
                                                            int outHeight)
Find the edges of the input image using the upper left corner pixel color as the background color, automatically crop the image down to eliminate the excess background border, then scale the image (maintaining the correct aspect ratio of the input image) and then center the image with appropriate background padding of the specified output width and height.

Returns:
The cropped and scaled image.

getPixels

public static int[] getPixels(java.awt.Image image)
Return the pixels (as 4-byte, 24-bit, 8-bit-per-component, ARGB ints). Note that the caller needs to track the dimensions (width,height) for subsequent manipulation.


getPixel

public static int getPixel(int[] pixels,
                           int width,
                           int x,
                           int y)
Return one pixel (as 4-byte, 24-bit, 8-bit-per-component, ARGB int) given the raw pixel array returned by the getPixels method.


findEdges

public static int[] findEdges(int[] pixels,
                              int width,
                              int height)
Find the edges of the image by finding the min/max x,y coordinate where pixels are a different color than the upper left pixel.

Returns:
int[4] (left,top,right,bottom)

main

public static void main(java.lang.String[] args)
Unit testing entry point.

argv[0] = input image file name.
argv[1] = output JPEG image file name.
argv[2] = output image width.
argv[3] = output image height.

Example: java ImageUtils inFile.png outFile.jpg 512 512