rebuild.util
Class GraphicsUtilities

java.lang.Object
  extended by rebuild.util.GraphicsUtilities

public final class GraphicsUtilities
extends java.lang.Object

A collection of various Graphics utilities.

Since:
BBX 1.0.1

Field Summary
static int BMP
          Windows Bitmap (BMP) format.
static int GIF
          GIF format.
static int JPEG
          JPEG format.
static int PNG
          PNG format.
static int TIFF
          TIFF format.
static int WBMP
          Windows Bitmap (WBMP) format.
 
Method Summary
static EncodedImage bitmapToEncodedImage(Bitmap map)
          Convert a Bitmap to an EncodedImage.
static EncodedImage bitmapToEncodedImage(Bitmap map, boolean encodeAlpha)
          Convert a Bitmap to an EncodedImage.
static EncodedImage bitmapToEncodedImage(Bitmap map, boolean encodeAlpha, int type)
          Convert a Bitmap to an EncodedImage in the specified format.
static int colorFromArgb(int argb)
          Creates a Color from a 32-bit ARGB value.
static int colorFromArgb(int alpha, int baseColor)
          Creates a Color from the specified Color, but with the new specified alpha value.
static int colorFromArgb(int red, int green, int blue)
          Creates a Color from the specified 8-bit color values (red, green, and blue).
static int colorFromArgb(int alpha, int red, int green, int blue)
          Creates a Color from the four ARGB component (alpha, red, green, and blue) values.
static int colorGetAlpha(int argb)
          Get the alpha channel from the specified color.
static int colorGetBlue(int argb)
          Get the blue channel from the specified color.
static int colorGetGreen(int argb)
          Get the green channel from the specified color.
static int colorGetRed(int argb)
          Get the red channel from the specified color.
static int colorSetAlpha(int argb, int value)
          Set the alpha channel in the specified color.
static int colorSetBlue(int argb, int value)
          Set the blue channel in the specified color.
static int colorSetGreen(int argb, int value)
          Set the green channel in the specified color.
static int colorSetRed(int argb, int value)
          Set the red channel in the specified color.
static int getPixel(Bitmap map, int x, int y)
          Get a pixel from a bitmap in AARRGGBB format.
static Bitmap loadBitmap(java.io.InputStream in)
          Load the specified Bitmap object.
static Bitmap loadBitmap(java.lang.String file)
          Load the specified Bitmap object.
static EncodedImage loadEncodedImage(java.io.InputStream in)
          Load the specified loadEncodedImage object.
static EncodedImage loadEncodedImage(java.lang.String file)
          Load the specified EncodedImage object.
static Image loadImage(java.io.InputStream in)
          Load the specified Image object.
static Image loadImage(java.lang.String file)
          Load the specified Image object.
static void saveBitmap(java.io.OutputStream out, Bitmap map, int format)
          Save a Bitmap to a OutputStream in a specified format.
static boolean saveBitmap(java.lang.String file, Bitmap map, int format)
          Save a Bitmap to a file in a specified format.
static void saveEncodedImage(java.io.OutputStream out, EncodedImage map)
          Save a EncodedImage to a OutputStream.
static boolean saveEncodedImage(java.lang.String file, EncodedImage map)
          Save a EncodedImage to a file.
static void saveImage(java.io.OutputStream out, Image map, int format)
          Save a Image to a OutputStream in a specified format.
static boolean saveImage(java.lang.String file, Image map, int format)
          Save a Image to a file in a specified format.
static void setPixel(Bitmap map, int color, int x, int y)
          Set a pixel in a bitmap in AARRGGBB format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BMP

public static final int BMP
Windows Bitmap (BMP) format.

See Also:
Constant Field Values

GIF

public static final int GIF
GIF format.

See Also:
Constant Field Values

JPEG

public static final int JPEG
JPEG format.

See Also:
Constant Field Values

PNG

public static final int PNG
PNG format.

See Also:
Constant Field Values

TIFF

public static final int TIFF
TIFF format.

See Also:
Constant Field Values

WBMP

public static final int WBMP
Windows Bitmap (WBMP) format. A very basic version of BMP.

See Also:
Constant Field Values
Method Detail

bitmapToEncodedImage

public static EncodedImage bitmapToEncodedImage(Bitmap map)
Convert a Bitmap to an EncodedImage. Alpha channel (if present) is decoded by default.

Parameters:
map - The Bitmap to convert.
Returns:
The resulting EncodedImage (in the format of a PNGEncodedImage). Null if an error occurred.

bitmapToEncodedImage

public static EncodedImage bitmapToEncodedImage(Bitmap map,
                                                boolean encodeAlpha)
Convert a Bitmap to an EncodedImage.

Parameters:
map - The Bitmap to convert.
encodeAlpha - True if alpha channel (if present) should be decoded/encoded.
Returns:
The resulting EncodedImage (in the format of a PNGEncodedImage). Null if an error occurred.

bitmapToEncodedImage

public static EncodedImage bitmapToEncodedImage(Bitmap map,
                                                boolean encodeAlpha,
                                                int type)
Convert a Bitmap to an EncodedImage in the specified format.

Parameters:
map - The Bitmap to convert.
encodeAlpha - True if alpha channel (if present) should be decoded/encoded. This will be ignored if the type does not support alpha.
type - One of the following formats to convert the Bitmap to: BMP, GIF, JPEG, PNG, TIFF, or WBMP. If a invalid format is specified then BMP is used.
Returns:
The resulting EncodedImage. Null if an error occurred.

getPixel

public static int getPixel(Bitmap map,
                           int x,
                           int y)
Get a pixel from a bitmap in AARRGGBB format.

Parameters:
map - The bitmap to get the pixel from.
x - The x pixel to get.
y - The y pixel to get.
Returns:
The resulting pixel in AARRGGBB format, -1 will be returned if map is null.

setPixel

public static void setPixel(Bitmap map,
                            int color,
                            int x,
                            int y)
Set a pixel in a bitmap in AARRGGBB format.

Parameters:
map - The bitmap to set the pixel on.
color - The pixel to set in AARRGGBB format.
The - x pixel to set.
The - y pixel to set.

colorFromArgb

public static int colorFromArgb(int argb)
Creates a Color from a 32-bit ARGB value.

Parameters:
argb - A value specifying the 32-bit ARGB value.
Returns:
The Color that this method creates.

colorFromArgb

public static int colorFromArgb(int alpha,
                                int baseColor)
Creates a Color from the specified Color, but with the new specified alpha value. Although this method allows a 32-bit value to be passed for the alpha value, the value is limited to 8 bits.

Parameters:
alpha - The alpha value for the new Color. Valid values are 0 through 255.
baseColor - The Color from which to create the new Color.
Returns:
The Color that this method creates.

colorFromArgb

public static int colorFromArgb(int red,
                                int green,
                                int blue)
Creates a Color from the specified 8-bit color values (red, green, and blue). The alpha value is implicitly 255 (fully opaque). Although this method allows a 32-bit value to be passed for each color component, the value of each component is limited to 8 bits.

Parameters:
red - The red component value for the new Color. Valid values are 0 through 255.
green - The green component value for the new Color. Valid values are 0 through 255.
blue - The blue component value for the new Color. Valid values are 0 through 255.
Returns:
The Color that this method creates.

colorFromArgb

public static int colorFromArgb(int alpha,
                                int red,
                                int green,
                                int blue)
Creates a Color from the four ARGB component (alpha, red, green, and blue) values. Although this method allows a 32-bit value to be passed for each component, the value of each component is limited to 8 bits.

Parameters:
alpha - The alpha component. Valid values are 0 through 255.
red - The red component. Valid values are 0 through 255.
green - The green component. Valid values are 0 through 255.
blue - The blue component. Valid values are 0 through 255.
Returns:
The Color that this method creates.

colorGetRed

public static int colorGetRed(int argb)
Get the red channel from the specified color.

Parameters:
argb - The ARGB color to get the red channel from.
Returns:
The red channel from the specified color.

colorGetGreen

public static int colorGetGreen(int argb)
Get the green channel from the specified color.

Parameters:
argb - The ARGB color to get the green channel from.
Returns:
The green channel from the specified color.

colorGetBlue

public static int colorGetBlue(int argb)
Get the blue channel from the specified color.

Parameters:
argb - The ARGB color to get the blue channel from.
Returns:
The blue channel from the specified color.

colorGetAlpha

public static int colorGetAlpha(int argb)
Get the alpha channel from the specified color.

Parameters:
argb - The ARGB color to get the alpha channel from.
Returns:
The alpha channel from the specified color.

colorSetRed

public static int colorSetRed(int argb,
                              int value)
Set the red channel in the specified color.

Parameters:
argb - The color to set the red channel for.
value - The value to set the red channel. Range is 0 - 255.
Returns:
The resulting color.

colorSetGreen

public static int colorSetGreen(int argb,
                                int value)
Set the green channel in the specified color.

Parameters:
argb - The color to set the green channel for.
value - The value to set the green channel. Range is 0 - 255.
Returns:
The resulting color.

colorSetBlue

public static int colorSetBlue(int argb,
                               int value)
Set the blue channel in the specified color.

Parameters:
argb - The color to set the blue channel for.
value - The value to set the blue channel. Range is 0 - 255.
Returns:
The resulting color.

colorSetAlpha

public static int colorSetAlpha(int argb,
                                int value)
Set the alpha channel in the specified color.

Parameters:
argb - The color to set the alpha channel for.
value - The value to set the alpha channel. Range is 0 - 255.
Returns:
The resulting color.

saveImage

public static boolean saveImage(java.lang.String file,
                                Image map,
                                int format)
Save a Image to a file in a specified format.

Parameters:
file - The path to save the Image to.
map - The Image to write.
format - One of the following formats to write the Image as: BMP, GIF, JPEG, PNG, TIFF, or WBMP. If a invalid format is specified then BMP is used.
Returns:
true if the Image was saved, false if otherwise.

saveImage

public static void saveImage(java.io.OutputStream out,
                             Image map,
                             int format)
Save a Image to a OutputStream in a specified format.

Parameters:
out - The OutputStream to write the Bitmap to.
map - The Image to write.
format - One of the following formats to write the Image as: BMP, GIF, JPEG, PNG, TIFF, or WBMP. If a invalid format is specified then BMP is used.

saveBitmap

public static boolean saveBitmap(java.lang.String file,
                                 Bitmap map,
                                 int format)
Save a Bitmap to a file in a specified format.

Parameters:
file - The path to save the Bitmap to.
map - The Bitmap to write.
format - One of the following formats to write the Bitmap as: BMP, GIF, JPEG, PNG, TIFF, or WBMP. If a invalid format is specified then BMP is used.
Returns:
true if the Bitmap was saved, false if otherwise.

saveBitmap

public static void saveBitmap(java.io.OutputStream out,
                              Bitmap map,
                              int format)
Save a Bitmap to a OutputStream in a specified format.

Parameters:
out - The OutputStream to write the Bitmap to.
map - The Bitmap to write.
format - One of the following formats to write the Bitmap as: BMP, GIF, JPEG, PNG, TIFF, or WBMP. If a invalid format is specified then BMP is used.

saveEncodedImage

public static boolean saveEncodedImage(java.lang.String file,
                                       EncodedImage map)
Save a EncodedImage to a file.

Parameters:
file - The path to save the EncodedImage to.
map - The EncodedImage to write.
Returns:
true if the EncodedImage was saved, false if otherwise.

saveEncodedImage

public static void saveEncodedImage(java.io.OutputStream out,
                                    EncodedImage map)
Save a EncodedImage to a OutputStream.

Parameters:
out - The OutputStream to write the EncodedImage to.
map - The EncodedImage to write.

loadImage

public static Image loadImage(java.lang.String file)
Load the specified Image object.

Parameters:
file - The path to the Image.
Returns:
The loaded Image.

loadImage

public static Image loadImage(java.io.InputStream in)
Load the specified Image object.

Parameters:
file - The InputStream to load the Image from.
Returns:
The loaded Image.

loadBitmap

public static Bitmap loadBitmap(java.lang.String file)
Load the specified Bitmap object.

Parameters:
file - The path to the Bitmap.
Returns:
The loaded Bitmap.

loadBitmap

public static Bitmap loadBitmap(java.io.InputStream in)
Load the specified Bitmap object.

Parameters:
file - The InputStream to load the Bitmap from.
Returns:
The loaded Bitmap.

loadEncodedImage

public static EncodedImage loadEncodedImage(java.lang.String file)
Load the specified EncodedImage object.

Parameters:
file - The path to the EncodedImage.
Returns:
The loaded EncodedImage.

loadEncodedImage

public static EncodedImage loadEncodedImage(java.io.InputStream in)
Load the specified loadEncodedImage object.

Parameters:
file - The InputStream to load the loadEncodedImage from.
Returns:
The loaded loadEncodedImage.