ch.aplu.util
Class GBitmap

java.lang.Object
  extended by java.awt.Image
      extended by java.awt.image.BufferedImage
          extended by ch.aplu.util.GBitmap
All Implemented Interfaces:
java.awt.image.RenderedImage, java.awt.image.WritableRenderedImage, java.awt.Transparency

public class GBitmap
extends java.awt.image.BufferedImage

GBitmap is a helper class derived from BufferedImage with some common bitmap transformation methods.


Field Summary
 
Fields inherited from class java.awt.image.BufferedImage
TYPE_3BYTE_BGR, TYPE_4BYTE_ABGR, TYPE_4BYTE_ABGR_PRE, TYPE_BYTE_BINARY, TYPE_BYTE_GRAY, TYPE_BYTE_INDEXED, TYPE_CUSTOM, TYPE_INT_ARGB, TYPE_INT_ARGB_PRE, TYPE_INT_BGR, TYPE_INT_RGB, TYPE_USHORT_555_RGB, TYPE_USHORT_565_RGB, TYPE_USHORT_GRAY
 
Fields inherited from class java.awt.Image
SCALE_AREA_AVERAGING, SCALE_DEFAULT, SCALE_FAST, SCALE_REPLICATE, SCALE_SMOOTH, UndefinedProperty
 
Fields inherited from interface java.awt.Transparency
BITMASK, OPAQUE, TRANSLUCENT
 
Constructor Summary
GBitmap(java.awt.image.ColorModel cm, java.awt.image.WritableRaster raster, boolean isRasterPremultiplied, java.util.Hashtable properties)
          Constructs a BufferedImage with a specified ColorModel and Raster.
GBitmap(int width, int height)
          Constructs a BufferedImage of type BufferedImage.TYPE_INT_ARGB.
GBitmap(int width, int height, int imageType)
          Constructs a BufferedImage of one of the predefined image types.
GBitmap(int width, int height, int imageType, java.awt.image.IndexColorModel cm)
          Constructs a BufferedImage of one of the predefined image types: TYPE_BYTE_BINARY or TYPE_BYTE_INDEXED.
 
Method Summary
static GBitmap crop(java.awt.image.BufferedImage bi, int x1, int y1, int x2, int y2)
          Extracts the partial image if the given rectangular area.
static GBitmap floodFill(java.awt.image.BufferedImage bi, java.awt.Point pt, java.awt.Color oldColor, java.awt.Color newColor)
          Fills a bounded single-colored region with the given color.
static byte[] getByteArray(java.awt.image.BufferedImage sourceImage, java.lang.String imageFormat)
          Returns the image in a byte array. imageFormat is the informal name of the format (one of the strings returned by get SupportedImageFormats()).
 java.awt.Color getPixelColor(int[] pt)
          Returns the color of the pixel at given point (defined as int array for Jython compatibility).
 java.awt.Color getPixelColor(int x, int y)
          Returns the color of the pixel at given x,y coordinates.
 java.lang.String getPixelColorStr(int[] pt)
          Returns the X11 color name of the pixel at given point (defined as int array for Jython compatibility).
 java.lang.String getPixelColorStr(int x, int y)
          Returns the X11 color name of the pixel at given x,y coordinates.
static java.lang.String[] getSupportedImageFormats()
          Returns all supported image formats.
static GBitmap paste(java.awt.image.BufferedImage original, java.awt.image.BufferedImage replacement, int xStart, int yStart)
          Returns a clone of the original image where a part is replaced by another image.
static boolean save(java.awt.image.BufferedImage bi, java.lang.String filename, java.lang.String type)
          Writes a image file of the given BufferedImage.
static GBitmap scale(java.awt.image.BufferedImage bi, double factor, double angle)
          Transforms the given buffered image by scaling by the given factor and rotating by the given angle.
 void setPixelColor(int[] pt, java.awt.Color color)
          Modifies the color of the pixel at given point (defined as int array for Jython compatibility).
 void setPixelColor(int x, int y, java.awt.Color color)
          Modifies the color of the pixel at given x, y coordinates.
 void setPixelColorStr(int[] pt, java.lang.String colorStr)
          Modifies the color (defined as X11 color name) of the pixel at given point (defined as int array for Jython compatibility).
 void setPixelColorStr(int x, int y, java.lang.String colorStr)
          Modifies the color (defined as X11 color name) of the pixel at given x, y coordinates.
static GBitmap setTransparency(java.awt.image.BufferedImage bi, double factor)
          Returns a clone of the given image where each pixel has a new transparency value (alpha component in the ARGB color model).
 
Methods inherited from class java.awt.image.BufferedImage
addTileObserver, coerceData, copyData, createGraphics, getAlphaRaster, getColorModel, getData, getData, getGraphics, getHeight, getHeight, getMinTileX, getMinTileY, getMinX, getMinY, getNumXTiles, getNumYTiles, getProperty, getProperty, getPropertyNames, getRaster, getRGB, getRGB, getSampleModel, getSource, getSources, getSubimage, getTile, getTileGridXOffset, getTileGridYOffset, getTileHeight, getTileWidth, getTransparency, getType, getWidth, getWidth, getWritableTile, getWritableTileIndices, hasTileWriters, isAlphaPremultiplied, isTileWritable, releaseWritableTile, removeTileObserver, setData, setRGB, setRGB, toString
 
Methods inherited from class java.awt.Image
flush, getAccelerationPriority, getCapabilities, getScaledInstance, setAccelerationPriority
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GBitmap

public GBitmap(java.awt.image.ColorModel cm,
               java.awt.image.WritableRaster raster,
               boolean isRasterPremultiplied,
               java.util.Hashtable properties)
Constructs a BufferedImage with a specified ColorModel and Raster.


GBitmap

public GBitmap(int width,
               int height,
               int imageType)
Constructs a BufferedImage of one of the predefined image types.


GBitmap

public GBitmap(int width,
               int height)
Constructs a BufferedImage of type BufferedImage.TYPE_INT_ARGB.


GBitmap

public GBitmap(int width,
               int height,
               int imageType,
               java.awt.image.IndexColorModel cm)
Constructs a BufferedImage of one of the predefined image types: TYPE_BYTE_BINARY or TYPE_BYTE_INDEXED.

Method Detail

getPixelColor

public java.awt.Color getPixelColor(int x,
                                    int y)
Returns the color of the pixel at given x,y coordinates.


getPixelColor

public java.awt.Color getPixelColor(int[] pt)
Returns the color of the pixel at given point (defined as int array for Jython compatibility).


getPixelColorStr

public java.lang.String getPixelColorStr(int x,
                                         int y)
Returns the X11 color name of the pixel at given x,y coordinates.


getPixelColorStr

public java.lang.String getPixelColorStr(int[] pt)
Returns the X11 color name of the pixel at given point (defined as int array for Jython compatibility).


setPixelColor

public void setPixelColor(int x,
                          int y,
                          java.awt.Color color)
Modifies the color of the pixel at given x, y coordinates.


setPixelColor

public void setPixelColor(int[] pt,
                          java.awt.Color color)
Modifies the color of the pixel at given point (defined as int array for Jython compatibility).


setPixelColorStr

public void setPixelColorStr(int x,
                             int y,
                             java.lang.String colorStr)
Modifies the color (defined as X11 color name) of the pixel at given x, y coordinates.


setPixelColorStr

public void setPixelColorStr(int[] pt,
                             java.lang.String colorStr)
Modifies the color (defined as X11 color name) of the pixel at given point (defined as int array for Jython compatibility).


save

public static boolean save(java.awt.image.BufferedImage bi,
                           java.lang.String filename,
                           java.lang.String type)
Writes a image file of the given BufferedImage. Normally the following image formats are supported: bmp, gif, jpg, png, but call getSupportedImageFormats() to find all formats supported by the current platform.

Parameters:
bi - the given BufferedImage to copy
filename - the path to the image file
type - the image file format like "bmp", "gif", "jpg", "png" (all lowercase)
Returns:
true, if the format is supported and the file was successfully written; otherwise false

floodFill

public static GBitmap floodFill(java.awt.image.BufferedImage bi,
                                java.awt.Point pt,
                                java.awt.Color oldColor,
                                java.awt.Color newColor)
Fills a bounded single-colored region with the given color. The given point is part of the region and used to specify it.

Parameters:
bi - the BufferedImage containing the connected region
pt - a point inside the region
oldColor - the old color of the region
newColor - the new color of the region
Returns:
a new BufferedImage with the transformed region, the given BufferedImage remains unchanged

setTransparency

public static GBitmap setTransparency(java.awt.image.BufferedImage bi,
                                      double factor)
Returns a clone of the given image where each pixel has a new transparency value (alpha component in the ARGB color model). The new transparency value is the old value multiplied by the transparency multiplier (limited to 0..255).

Parameters:
bi - the original image
factor - the transparency multiplier
Returns:
the transformed image (the given image is unchanged)

crop

public static GBitmap crop(java.awt.image.BufferedImage bi,
                           int x1,
                           int y1,
                           int x2,
                           int y2)
Extracts the partial image if the given rectangular area. Extracted pixels outside the given image are set to white.

Parameters:
bi - the image where to extract the partial image
x1 - the x-coordinate of one of the rectangle vertex
y1 - the y-coordinate of this vertex
x2 - the x-coordinate of the opposite vertex
y2 - the y-coordinate of this vertex
Returns:
the extracted image (the given image is unchanged)

paste

public static GBitmap paste(java.awt.image.BufferedImage original,
                            java.awt.image.BufferedImage replacement,
                            int xStart,
                            int yStart)
Returns a clone of the original image where a part is replaced by another image.

Parameters:
original - the original image
replacement - the image to insert
xStart - the upper left x-coordinate where the replacement starts
yStart - the upper left y-coordinate where the replacement starts
Returns:
the modified image (the original image is unchanged)

scale

public static GBitmap scale(java.awt.image.BufferedImage bi,
                            double factor,
                            double angle)
Transforms the given buffered image by scaling by the given factor and rotating by the given angle.

Parameters:
bi - the buffered image to transform (unchanged)
factor - the zoom factor (>1 zoom-in, <1 zoom-out)
angle - the rotation angle (in degrees clockwise)
Returns:
the transformed image

getSupportedImageFormats

public static java.lang.String[] getSupportedImageFormats()
Returns all supported image formats.

Returns:
a string array containing all image format descriptions of the current platform.

getByteArray

public static byte[] getByteArray(java.awt.image.BufferedImage sourceImage,
                                  java.lang.String imageFormat)
Returns the image in a byte array. imageFormat is the informal name of the format (one of the strings returned by get SupportedImageFormats()).

Returns:
the image data as byte array, null if the image format is not supported