cbr.util
Class Images

java.lang.Object
  extended bycbr.util.Images

public class Images
extends Object

This class provides general support methods for CBR applications such as image loading.

Version:
"$Id: Images.java 1913 2007-08-08 02:41:53Z jpeters $"
Author:
Volker Roth

Field Summary
static int BUF_SIZE
          The size of the buffer used to load images.
protected static int counter_
          A sequence counter for image IDs.
static int MAX_LEN
          The maximum number of bytes an encoded image may have when reading it via an input stream.
protected static MediaTracker tracker_
          The media tracker instance used for waiting until an image is loaded.
 
Constructor Summary
private Images()
          No-one may instantiate this class.
 
Method Summary
static int[] getPixels(Image im)
          This method grabs the pixels of the given image into an integer array.
static Image newImage(byte[] b)
          This method creates a new image from the data in the given byte array.
static Image newImage(InputStream in)
          This method reads an image from the given input stream.
static Image newImage(int[] px, int w, int h)
          This method takes an array of integers of RGB values and returns an image instance.
static Image newImage(URL url)
          This method creates a new image from the data read from the given URL.
static Image waitForImage(Image im)
          This method waits until the image is loaded.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_LEN

public static final int MAX_LEN
The maximum number of bytes an encoded image may have when reading it via an input stream. If the image is bigger then an IOException is thrown.

See Also:
Constant Field Values

BUF_SIZE

public static final int BUF_SIZE
The size of the buffer used to load images.

See Also:
Constant Field Values

tracker_

protected static MediaTracker tracker_
The media tracker instance used for waiting until an image is loaded. Beware, calling the image gathering methods of this instance from different threads will block all of them until all images are loaded.


counter_

protected static int counter_
A sequence counter for image IDs.

Constructor Detail

Images

private Images()
No-one may instantiate this class.

Method Detail

newImage

public static Image newImage(InputStream in)
                      throws IOException,
                             ImageException,
                             InterruptedException
This method reads an image from the given input stream. The input stream is closed after reading the image.

Parameters:
in - The input stream
Returns:
The image.
Throws:
ImageException - if an error occurs during loading the image.
InterruptedException - if an interrupt is raised during loading the image.
IOException - if guess what...

newImage

public static Image newImage(byte[] b)
                      throws ImageException,
                             InterruptedException
This method creates a new image from the data in the given byte array.

Parameters:
b - The byte array holding the encoded image data.
Returns:
The image.
Throws:
ImageException - if an error occurs during loading the image.
InterruptedException - if an interrupt is raised during loading the image.

newImage

public static Image newImage(URL url)
                      throws ImageException,
                             InterruptedException
This method creates a new image from the data read from the given URL.

Parameters:
url - The URL pointing to the encoded image data.
Returns:
The image.
Throws:
ImageException - if an error occurs during loading the image.
InterruptedException - if an interrupt is raised during loading the image.

waitForImage

public static Image waitForImage(Image im)
                          throws ImageException,
                                 InterruptedException
This method waits until the image is loaded. It uses a media tracker to do this.

Parameters:
im - The image to wait for. If null is passed then this method returns immediately with a null.
Throws:
ImageException - if an error occurs during loading the image.
InterruptedException - if an interrupt is raised during loading the image.

getPixels

public static int[] getPixels(Image im)
                       throws ImageException,
                              InterruptedException
This method grabs the pixels of the given image into an integer array. The size of the array is exactly the number of pixels in the image; each pixel is in the RGB color model. The image must be loaded already and the image's width and height must be set.

Returns:
The pixel array.
Throws:
IllegalArgumentException - if the image's width and height is either not known or null.
ImageException - if an error occurs while grabbing pixels.
InterruptedException - if an interrupt is raised while grabbing pixels.

newImage

public static Image newImage(int[] px,
                             int w,
                             int h)
This method takes an array of integers of RGB values and returns an image instance.

Parameters:
px - The pixel data.
w - The width of the image in pixels.
h - The height of the image in pixels.


Copyright © Fraunhofer Gesellschaft. All Rights Reserved.