com.bbn.openmap.image
Class BufferedImageHelper

java.lang.Object
  |
  +--com.bbn.openmap.image.BufferedImageHelper

public class BufferedImageHelper
extends java.lang.Object

This class provides some utility methods for creating a BufferedImage. It will check to see if the Java Advanced Image package is available and use it if it can.

Author:
dietrick - original implemenation and reflection mods., Fredrik Lyden - JAI inspiration and initial code.

Method Summary
static java.awt.image.BufferedImage getBufferedImage(java.awt.Image image, int x, int y, int w, int h)
          Return a BufferedImage loaded from a Image.
static java.awt.image.BufferedImage getBufferedImage(java.awt.Image image, int x, int y, int w, int h, int imageType)
          Return a BufferedImage loaded from a Image.
static java.awt.image.BufferedImage getBufferedImage(java.lang.String path)
          Return a BufferedImage loaded from a file path.
static java.awt.image.BufferedImage getBufferedImage(java.lang.String path, int x, int y, int w, int h)
          Return a BufferedImage loaded from an image file path.
static java.awt.image.BufferedImage getBufferedImage(java.net.URL url)
          Return a BufferedImage loaded from a URL.
static java.awt.image.BufferedImage getBufferedImage(java.net.URL url, int x, int y, int w, int h)
          Return a BufferedImage loaded from a URL.
static java.awt.image.BufferedImage getBufferedImageFromPixelGrabber(java.awt.Image image, int x, int y, int w, int h, int imageType)
          Return a BufferedImage loaded from a Image, using a PixelGrabber.
protected static java.lang.Object getJAI()
          Get the JAI class if it's available.
static java.awt.image.BufferedImage getJAIBufferedImage(java.lang.String opName, java.lang.Object param)
          Run the operation on JAI to create BufferedImage.
static java.awt.image.BufferedImage getJAIBufferedImage(java.lang.String opName, java.lang.Object param, int x, int y, int w, int h)
          Run the operation on JAI to create BufferedImage.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getJAI

protected static java.lang.Object getJAI()
Get the JAI class if it's available.


getJAIBufferedImage

public static java.awt.image.BufferedImage getJAIBufferedImage(java.lang.String opName,
                                                               java.lang.Object param)
Run the operation on JAI to create BufferedImage. Uses reflection to determine if JAI is available.

Parameters:
opName - JAI opName, like "file" or "url"
param - JAI object to use for operation, like the file path (String) or URL.
Returns:
BufferedImage if JAI can be used to create it, null if anything goes wrong.

getJAIBufferedImage

public static java.awt.image.BufferedImage getJAIBufferedImage(java.lang.String opName,
                                                               java.lang.Object param,
                                                               int x,
                                                               int y,
                                                               int w,
                                                               int h)
                                                        throws java.lang.InterruptedException
Run the operation on JAI to create BufferedImage. Uses reflection to determine if JAI is available. If x or y is not zero, or w and h are not the image dimensions, the image returned will be cropped/translated to match the values.

Parameters:
opName - JAI opName, like "file" or "url"
param - JAI object to use for operation, like the file path (String) or URL.
x - x start pixel
y - y start pixel
w - crop width (-1 uses image width)
h - crop height (-1 uses image height)
Returns:
BufferedImage if JAI can be used to create it, null if anything goes wrong.
Throws:
java.lang.InterruptedException

getBufferedImage

public static java.awt.image.BufferedImage getBufferedImage(java.net.URL url)
                                                     throws java.lang.InterruptedException
Return a BufferedImage loaded from a URL.

Returns:
BufferedImage if it can be created, null if anything goes wrong.
Throws:
java.lang.InterruptedException

getBufferedImage

public static java.awt.image.BufferedImage getBufferedImage(java.net.URL url,
                                                            int x,
                                                            int y,
                                                            int w,
                                                            int h)
                                                     throws java.lang.InterruptedException
Return a BufferedImage loaded from a URL.

Parameters:
url - the source URL
x - x start pixel
y - y start pixel
w - crop width (-1 uses image width)
h - crop height (-1 uses image height)
Returns:
BufferedImage if it can be created, null if anything goes wrong.
Throws:
java.lang.InterruptedException

getBufferedImage

public static java.awt.image.BufferedImage getBufferedImage(java.lang.String path)
                                                     throws java.lang.InterruptedException
Return a BufferedImage loaded from a file path.

Returns:
BufferedImage if it can be created, null if anything goes wrong.
Throws:
java.lang.InterruptedException

getBufferedImage

public static java.awt.image.BufferedImage getBufferedImage(java.lang.String path,
                                                            int x,
                                                            int y,
                                                            int w,
                                                            int h)
                                                     throws java.lang.InterruptedException
Return a BufferedImage loaded from an image file path.

Parameters:
path - file path to the image
x - x start pixel
y - y start pixel
w - crop width (-1 uses image width)
h - crop height (-1 uses image height)
Returns:
BufferedImage if it can be created, null if anything goes wrong.
Throws:
java.lang.InterruptedException

getBufferedImage

public static java.awt.image.BufferedImage getBufferedImage(java.awt.Image image,
                                                            int x,
                                                            int y,
                                                            int w,
                                                            int h)
                                                     throws java.lang.InterruptedException
Return a BufferedImage loaded from a Image. The type of image is BufferedImage.Type_INT_RGB. If you know the height and width, use them because it's slower to have the class figure it out.

Parameters:
image - the source Image
x - x start pixel
y - y start pixel
w - crop width (-1 uses image width)
h - crop height (-1 uses image height)
Returns:
BufferedImage if it can be created, null if anything goes wrong.
Throws:
java.lang.InterruptedException

getBufferedImage

public static java.awt.image.BufferedImage getBufferedImage(java.awt.Image image,
                                                            int x,
                                                            int y,
                                                            int w,
                                                            int h,
                                                            int imageType)
                                                     throws java.lang.InterruptedException
Return a BufferedImage loaded from a Image. If you know the height and width, use them because it's slower to have the class figure it out.

Parameters:
image - the source Image
x - x start pixel - the horizontal pixel location in the returned image that the provided image will be set.
y - y start pixel - the vertical pixel location in the returned image that the provided image will be set.
w - crop width (-1 uses image width)
h - crop height (-1 uses image height)
imageType - the image color model. See BufferedImage.
Returns:
BufferedImage if it can be created, null if anything goes wrong.
Throws:
java.lang.InterruptedException

getBufferedImageFromPixelGrabber

public static java.awt.image.BufferedImage getBufferedImageFromPixelGrabber(java.awt.Image image,
                                                                            int x,
                                                                            int y,
                                                                            int w,
                                                                            int h,
                                                                            int imageType)
Return a BufferedImage loaded from a Image, using a PixelGrabber. Good for when you have an Image, not a BufferedImage, and don't know the width and height. There is a performance penalty with this method, though.

Parameters:
image - the source Image
x - x start pixel - the horizontal pixel location in the returned image that the provided image will be set.
y - y start pixel - the vertical pixel location in the returned image that the provided image will be set.
w - crop width (-1 uses image width)
h - crop height (-1 uses image height)
imageType - the image color model. See BufferedImage.
Returns:
BufferedImage if it can be created, null if anything goes wrong.


Copyright (C) BBNT Solutions LLC; See http://openmap.bbn.com/ for details