waba.fx
Class Image

waba.lang.Object
  |
  +--waba.fx.Image

public class Image
extends Object
implements ISurface

Image is a rectangular image.

You can draw into an image and copy an image to a surface using a Graphics object.

See Also:
Graphics

Constructor Summary
Image(int width, int height)
          Creates an image of the specified width and height.
Image(String path)
          Loads and constructs an image from a file.
 
Method Summary
 void free()
          Sets the image width and height to 0 and frees any systems resources associated with the image.
 int getHeight()
          Returns the height of the image.
 int getWidth()
          Returns the width of the image.
 void setPixels(int bitsPerPixel, int[] colorMap, int bytesPerRow, int numRows, int y, byte[] pixels)
          Sets one or more row(s) of pixels in an image.
 
Methods inherited from class waba.lang.Object
toString
 

Constructor Detail

Image

public Image(int width,
             int height)
Creates an image of the specified width and height. The image has a color depth (number of bitplanes) and color map that matches the default drawing surface.

Image

public Image(String path)
Loads and constructs an image from a file. The path given is the path to the image file. The file must be in 2, 16 or 256 color uncompressed BMP bitmap format. If the image cannot be loaded, the image constructed will have a width and height of 0.
Method Detail

setPixels

public void setPixels(int bitsPerPixel,
                      int[] colorMap,
                      int bytesPerRow,
                      int numRows,
                      int y,
                      byte[] pixels)
Sets one or more row(s) of pixels in an image. This method sets the values of a number of pixel rows in an image and is commonly used when writing code to load an image from a stream such as a file. The source pixels byte array must be in 1, 4 or 8 bit per pixel format with a matching color map size of 2, 16 or 256 colors.

Each color in the color map of the source pixels is identified by a single integer value. The integer is composed of 8 bits (value [0..255]) of red, green and blue using the following calculation:

 int color = (red << 16) | (green << 8) | blue;
 
As an example, to load a 16 color image, we would pass bitsPerPixel as 4 and would create a int array of 16 values for the color map. Then we would set each of the values in the color map to the colors used using the equation above. We could then either read data line by line from the source stream, calling this method for each row of pixels or could read a number of rows at once and then call this method to set the pixels.

The former approach uses less memory, the latter approach is faster.

Parameters:
bitsPerPixel - bits per pixel of the source pixels (1, 4 or 8)
colorMap - the color map of the source pixels (must be 2, 16 or 256 in length)
bytesPerRow - number of bytes per row of pixels in the source pixels array
numRows - the number of rows of pixels in the source pixels array
y - y coordinate in the image to start setting pixels
pixels - array containing the source pixels

free

public void free()
Sets the image width and height to 0 and frees any systems resources associated with the image.

getHeight

public int getHeight()
Returns the height of the image.

getWidth

public int getWidth()
Returns the width of the image.