com.jhlabs.image
Class ImageUtils

java.lang.Object
  extended by com.jhlabs.image.ImageUtils

public abstract class ImageUtils
extends java.lang.Object

A class containing some static utility methods for dealing with BufferedImages.


Constructor Summary
ImageUtils()
           
 
Method Summary
static java.awt.image.BufferedImage cloneImage(java.awt.image.BufferedImage image)
          Clones a BufferedImage.
static void composeThroughMask(java.awt.image.Raster src, java.awt.image.WritableRaster dst, java.awt.image.Raster sel)
          Compose src onto dst using the alpha of sel to interpolate between the two.
static java.awt.image.BufferedImage convertImageToARGB(java.awt.Image image)
          Convert an Image into a TYPE_INT_ARGB BufferedImage.
static java.awt.image.BufferedImage createImage(java.awt.image.ImageProducer producer)
          Cretae a BufferedImage from an ImageProducer.
static int[] getRGB(java.awt.image.BufferedImage image, int x, int y, int width, int height, int[] pixels)
          A convenience method for getting ARGB pixels from an image.
static java.awt.Rectangle getSelectedBounds(java.awt.image.BufferedImage p)
          Calculates the bounds of the non-transparent parts of the given image.
static java.awt.image.BufferedImage getSubimage(java.awt.image.BufferedImage image, int x, int y, int w, int h)
          Returns a *copy* of a subimage of image.
static void paintCheckedBackground(java.awt.Component c, java.awt.Graphics g, int x, int y, int width, int height)
          Paint a check pattern, used for a background to indicate image transparency.
static void setRGB(java.awt.image.BufferedImage image, int x, int y, int width, int height, int[] pixels)
          A convenience method for setting ARGB pixels in an image.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ImageUtils

public ImageUtils()
Method Detail

createImage

public static java.awt.image.BufferedImage createImage(java.awt.image.ImageProducer producer)
Cretae a BufferedImage from an ImageProducer.

Parameters:
producer - the ImageProducer
Returns:
a new TYPE_INT_ARGB BufferedImage

convertImageToARGB

public static java.awt.image.BufferedImage convertImageToARGB(java.awt.Image image)
Convert an Image into a TYPE_INT_ARGB BufferedImage. If the image is already of this type, the original image is returned unchanged.

Parameters:
image - the image to convert
Returns:
the converted image

getSubimage

public static java.awt.image.BufferedImage getSubimage(java.awt.image.BufferedImage image,
                                                       int x,
                                                       int y,
                                                       int w,
                                                       int h)
Returns a *copy* of a subimage of image. This avoids the performance problems associated with BufferedImage.getSubimage.

Parameters:
image - the image
x - the x position
y - the y position
w - the width
h - the height
Returns:
the subimage

cloneImage

public static java.awt.image.BufferedImage cloneImage(java.awt.image.BufferedImage image)
Clones a BufferedImage.

Parameters:
image - the image to clone
Returns:
the cloned image

paintCheckedBackground

public static void paintCheckedBackground(java.awt.Component c,
                                          java.awt.Graphics g,
                                          int x,
                                          int y,
                                          int width,
                                          int height)
Paint a check pattern, used for a background to indicate image transparency.

Parameters:
c - the component to draw into
g - the Graphics objects
x - the x position
y - the y position
width - the width
height - the height

getSelectedBounds

public static java.awt.Rectangle getSelectedBounds(java.awt.image.BufferedImage p)
Calculates the bounds of the non-transparent parts of the given image.

Parameters:
p - the image
Returns:
the bounds of the non-transparent area

composeThroughMask

public static void composeThroughMask(java.awt.image.Raster src,
                                      java.awt.image.WritableRaster dst,
                                      java.awt.image.Raster sel)
Compose src onto dst using the alpha of sel to interpolate between the two. I can't think of a way to do this using AlphaComposite.

Parameters:
src - the source raster
dst - the destination raster
sel - the mask raster

getRGB

public static int[] getRGB(java.awt.image.BufferedImage image,
                           int x,
                           int y,
                           int width,
                           int height,
                           int[] pixels)
A convenience method for getting ARGB pixels from an image. This tries to avoid the performance penalty of BufferedImage.getRGB unmanaging the image.

Parameters:
image - a BufferedImage object
x - the left edge of the pixel block
y - the right edge of the pixel block
width - the width of the pixel arry
height - the height of the pixel arry
pixels - the array to hold the returned pixels. May be null.
Returns:
the pixels
See Also:
setRGB(java.awt.image.BufferedImage, int, int, int, int, int[])

setRGB

public static void setRGB(java.awt.image.BufferedImage image,
                          int x,
                          int y,
                          int width,
                          int height,
                          int[] pixels)
A convenience method for setting ARGB pixels in an image. This tries to avoid the performance penalty of BufferedImage.setRGB unmanaging the image.

Parameters:
image - a BufferedImage object
x - the left edge of the pixel block
y - the right edge of the pixel block
width - the width of the pixel arry
height - the height of the pixel arry
pixels - the array of pixels to set
See Also:
getRGB(java.awt.image.BufferedImage, int, int, int, int, int[])