au.com.zip.cs
Class ImageUtil

java.lang.Object
  extended by au.com.zip.cs.ImageUtil

public class ImageUtil
extends Object

Assorted utility operations for Images.

Author:
Cameron Simpson <cs@zip.com.au> 30apr2003

Field Summary
static int CENTER
           
static int EAST
           
static int NORTH
           
static int NORTHEAST
           
static int NORTHWEST
           
static int SOUTH
           
static int SOUTHEAST
           
static int SOUTHWEST
           
static int WEST
           
 
Constructor Summary
ImageUtil()
           
 
Method Summary
static Point alignTopLeft(int x, int y, int width, int height, int orientation)
          Compute the top left Point for a rectangle of the specified width and height aligned with repect to the specified location (x,y) using the supplied orientation.
static BufferedImage copyImage(Image image)
          Return a new BufferedImage containing a copy of the current contents of the supplied Image.
static int getHeight(Image image)
          Return the height of an Image.
static Image getImage(String pathname)
          Return a new Image attached to image file supplied.
static int getWidth(Image image)
          Return the width of an Image.
static void label(Graphics g, String text, int x, int y, Color bg, Color outline, int orientation)
          Write a text label for the specified coordinates.
static void label(Image im, String text, double x, double y, Color fg, Color bg, Color outline, int orientation)
          Write a text label for the specified coordinates.
static Rectangle labelBounds(Graphics g, String text, int x, int y, boolean outlined, int orientation)
          Compute the bounds of a text label for the specified coordinates aligned as for label(Graphics,String,int,int,Color,Color,int).
static Rectangle labelBounds(Image im, String text, double x, double y, boolean outlined, int orientation)
          Compute the bounds of a text label for the specified coordinates aligned as for label(Graphics,String,int,int,Color,Color,int).
static Image loadImage(String pathname)
          Return a new Image attached to the image file supplied but don't return until all pixels have been loaded.
static int parseOrientation(String hint)
           
static RenderedImage renderImage(Image image)
          Return a new RenderedImage from the supplied Image.
static boolean saveImage(Image image, String pathname, String format)
          Just a wrapper for ImageIO.write(RenderedImage,String,File) that will accept an Image.
static void waitFor(Image image, int infoflags)
          Wait for the specified flags to be available for this Image.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CENTER

public static final int CENTER
See Also:
Constant Field Values

NORTH

public static final int NORTH
See Also:
Constant Field Values

SOUTH

public static final int SOUTH
See Also:
Constant Field Values

EAST

public static final int EAST
See Also:
Constant Field Values

WEST

public static final int WEST
See Also:
Constant Field Values

NORTHEAST

public static final int NORTHEAST
See Also:
Constant Field Values

NORTHWEST

public static final int NORTHWEST
See Also:
Constant Field Values

SOUTHEAST

public static final int SOUTHEAST
See Also:
Constant Field Values

SOUTHWEST

public static final int SOUTHWEST
See Also:
Constant Field Values
Constructor Detail

ImageUtil

public ImageUtil()
Method Detail

getImage

public static final Image getImage(String pathname)
Return a new Image attached to image file supplied.

Parameters:
pathname - the Image file pathname
Returns:
the Image

loadImage

public static final Image loadImage(String pathname)
Return a new Image attached to the image file supplied but don't return until all pixels have been loaded.

Parameters:
pathname - the Image file pathname
Returns:
the Image, or null if interrupted

waitFor

public static final void waitFor(Image image,
                                 int infoflags)
                          throws InterruptedException
Wait for the specified flags to be available for this Image.

Parameters:
image - the Image
infoflags - the property bitmask
Throws:
InterruptedException
See Also:
ImageObserverThread, ImageObserver

saveImage

public static final boolean saveImage(Image image,
                                      String pathname,
                                      String format)
                               throws IOException,
                                      InterruptedException
Just a wrapper for ImageIO.write(RenderedImage,String,File) that will accept an Image.

Parameters:
image - the Image to save
pathname - the pathname of the file in which to save P@aram format the format of the file
Returns:
false if no appropriate writer is found
Throws:
IOException
InterruptedException

getWidth

public static final int getWidth(Image image)
                          throws InterruptedException
Return the width of an Image. Waits for the width to be available if necessary.

Parameters:
image - the Image
Returns:
the width
Throws:
InterruptedException

getHeight

public static final int getHeight(Image image)
                           throws InterruptedException
Return the height of an Image. Waits for the height to be available if necessary.

Parameters:
image - the Image
Returns:
the height
Throws:
InterruptedException

renderImage

public static final RenderedImage renderImage(Image image)
Return a new RenderedImage from the supplied Image. If the supplied image is a RenderedImage, simply return it rather than making a new one.

Parameters:
image - the Image to render
Returns:
the rendered image, possibly the original, or null if interrupted

copyImage

public static final BufferedImage copyImage(Image image)
Return a new BufferedImage containing a copy of the current contents of the supplied Image.

Parameters:
image - the Image to copy
Returns:
the new BufferedImage or null if interrupted

parseOrientation

public static final int parseOrientation(String hint)

label

public static final void label(Image im,
                               String text,
                               double x,
                               double y,
                               Color fg,
                               Color bg,
                               Color outline,
                               int orientation)
                        throws InterruptedException
Write a text label for the specified coordinates. Draw a background rectangle if bg is not null. Draw an outline for the rectangle if the outline is not null. Align label according to the specified orientation, which is an integer from the constants CENTER, NORTH, SOUTH, EAST, WEST, NORTHEAST, NORTHWEST, SOUTHEAST or SOUTHWEST.

Parameters:
im - the Image on which to draw
text - the label to write
x - the left location of the label rectangle, a ratio in the range 0.0 to 1.0
y - the bottom location of the label rectangle, a ratio in the range 0.0 to 1.0
fg - the foreground (text) Color
bg - the background Color, if any
outline - the outline Color, if any
orientation - the orientation hint
Throws:
InterruptedException

label

public static final void label(Graphics g,
                               String text,
                               int x,
                               int y,
                               Color bg,
                               Color outline,
                               int orientation)
Write a text label for the specified coordinates. Draw a background rectangle if bg is not null. Draw an outline for the rectangle if the outline is not null. Align label according to the specified orientation, which is an integer from the constants CENTER, NORTH, SOUTH, EAST, WEST, NORTHEAST, NORTHWEST, SOUTHEAST or SOUTHWEST.

Parameters:
g - the Graphics context
text - the label to write
x - the left location of the label rectangle
y - the bottom location of the label rectangle
bg - the background Color, if any
outline - the outline Color, if any
orientation - the orientation hint

labelBounds

public static final Rectangle labelBounds(Image im,
                                          String text,
                                          double x,
                                          double y,
                                          boolean outlined,
                                          int orientation)
                                   throws InterruptedException
Compute the bounds of a text label for the specified coordinates aligned as for label(Graphics,String,int,int,Color,Color,int).

Parameters:
im - the Image on which the label would be drawn
text - the label to write
x - the left location of the label rectangle, a ratio from 0.0 to 1.0
y - the bottom location of the label rectangle, a ratio from 0.0 to 1.0
outlined - whether the label is outlined
orientation - the orientation hint
Throws:
InterruptedException

labelBounds

public static final Rectangle labelBounds(Graphics g,
                                          String text,
                                          int x,
                                          int y,
                                          boolean outlined,
                                          int orientation)
Compute the bounds of a text label for the specified coordinates aligned as for label(Graphics,String,int,int,Color,Color,int).

Parameters:
g - the Graphics context
text - the label to write
x - the left location of the label rectangle
y - the bottom location of the label rectangle
outlined - whether the label is outlined
orientation - the orientation hint

alignTopLeft

public static final Point alignTopLeft(int x,
                                       int y,
                                       int width,
                                       int height,
                                       int orientation)
Compute the top left Point for a rectangle of the specified width and height aligned with repect to the specified location (x,y) using the supplied orientation.

Parameters:
x - the horizontal ordinate of the alignment location
y - the vertical ordinate of the alignment location
width - the width of the rectangle
height - the height of the rectangle
orientation - the orientation hint