util.ui
Class GraphicTools

java.lang.Object
  extended by util.ui.GraphicTools

public class GraphicTools
extends Object

Bundle of graphical utilities for common color and image alterations.

Version:
January 20, 2008

Method Summary
static BufferedImage buffer(Image image)
          Creates a buffered instance of the image.
static BufferedImage copy(Image image)
          Creates a deep copy of an image.
static void flip(BufferedImage image, boolean vertical)
          Create a mirror image along an axis.
static Color getGradient(Color first, Color second, double perPrim, boolean shiftAlpha)
          Returns a blend of two colors, leaning a given degree toward the first.
static Color getNegative(Color color)
          Provides the color with the opposite RGB values of a given color, retaining any alpha value.
static void grayscale(BufferedImage image)
          Removes all color from an image.
static void outline(BufferedImage image, Color target, Color replacement, int thickness)
          Replaces all instances of a color when it borders a different color.
static void outlineGradient(BufferedImage image, Color target, Color firstRep, Color secondRep, int thickness)
          Replaces all instances of a color when it borders a different color.
static void replaceColor(BufferedImage image, Color target, Color replacement)
          Replaces all instances of one color with another.
static BufferedImage rotateCCW(BufferedImage image)
          Creates an instance of the image rotated ninety degrees counter-clockwise.
static BufferedImage rotateCW(BufferedImage image)
          Creates an instance of the image rotated ninety degrees clockwise.
static Color setAlpha(Color color, int alpha)
          Provides a color with a given alpha transparency.
static void tint(BufferedImage image, Color shift, double percentage, boolean shiftAlpha)
          Shifts the hue (RGB values) of the image toward a certain color.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

buffer

public static BufferedImage buffer(Image image)
Creates a buffered instance of the image.

Parameters:
image - picture to be processed
Returns:
buffered instance of the image

copy

public static BufferedImage copy(Image image)
Creates a deep copy of an image.

Parameters:
image - picture to be processed
Returns:
copy of the image

setAlpha

public static Color setAlpha(Color color,
                             int alpha)
Provides a color with a given alpha transparency.

Parameters:
color - hue from which to draw the RGB values
alpha - transparency (alpha) value ranging 0-255
Returns:
color with alpha value
Throws:
IllegalArgumentException - if alpha value is outside valid bounds (0-255)

getNegative

public static Color getNegative(Color color)
Provides the color with the opposite RGB values of a given color, retaining any alpha value.

Parameters:
color - hue from which to determine negative
Returns:
color with opposite RGB values

getGradient

public static Color getGradient(Color first,
                                Color second,
                                double perPrim,
                                boolean shiftAlpha)
Returns a blend of two colors, leaning a given degree toward the first.

Parameters:
first - color to be blended
second - color to be blended
perPrim - percentage leniency toward first color
shiftAlpha - if true alpha values are blended, otherwise the first color's alpha is used
Throws:
IllegalArgumentException - if perPrim is greater than one or less than zero

replaceColor

public static void replaceColor(BufferedImage image,
                                Color target,
                                Color replacement)
Replaces all instances of one color with another.

Parameters:
image - picture to be processed
target - color to be replaced
replacement - replacement color to substitute

tint

public static void tint(BufferedImage image,
                        Color shift,
                        double percentage,
                        boolean shiftAlpha)
Shifts the hue (RGB values) of the image toward a certain color. This can be useful for lightening, darkening, as well as simply recoloring an image.

Parameters:
image - picture to be processed
shift - color to which to shift the hue
percentage - percentage to which to shift the RGB values
shiftAlpha - if true the alpha values are altered
Throws:
IllegalArgumentException - if percentage is greater than one or less than zero

grayscale

public static void grayscale(BufferedImage image)
Removes all color from an image. Original version written by Marty Stepp.

Parameters:
image - picture to be processed

outline

public static void outline(BufferedImage image,
                           Color target,
                           Color replacement,
                           int thickness)
Replaces all instances of a color when it borders a different color. This does not include diagonals.

Parameters:
image - picture to be processed
target - color to be replaced
replacement - color of outline
thickness - width of border by repeated iterations

outlineGradient

public static void outlineGradient(BufferedImage image,
                                   Color target,
                                   Color firstRep,
                                   Color secondRep,
                                   int thickness)
Replaces all instances of a color when it borders a different color. The fill is a gradient, gradually going from the first replacement to the second over the thickness of the border. This does not consider diagonal positions.

Parameters:
image - picture to be processed
target - color to be replaced
firstRep - initial color of outline
secondRep - ending color of outline
thickness - width of border by repeated iterations
Throws:
IllegalArgumentException - if thickness is less than zero

flip

public static void flip(BufferedImage image,
                        boolean vertical)
Create a mirror image along an axis. Original version written by Marty Stepp.

Parameters:
image - picture to be processed
vertical - swaps top/bottom if true, left/right otherwise

rotateCW

public static BufferedImage rotateCW(BufferedImage image)
Creates an instance of the image rotated ninety degrees clockwise. Image is of type RGBA.

Parameters:
image - picture to be processed
Returns:
rotated instance of the image

rotateCCW

public static BufferedImage rotateCCW(BufferedImage image)
Creates an instance of the image rotated ninety degrees counter-clockwise. Image is of type RGBA.

Parameters:
image - picture to be processed
Returns:
rotated instance of the image