helma.image
Class ImageWrapper

java.lang.Object
  extended by helma.image.ImageWrapper

public class ImageWrapper
extends java.lang.Object

Abstract base class for Image Wrappers.


Field Summary
protected  ImageGenerator generator
           
protected  int height
           
protected  java.awt.Image image
           
protected  int width
           
 
Constructor Summary
ImageWrapper(java.awt.Image image, ImageGenerator generator)
           
ImageWrapper(java.awt.Image image, int width, int height, ImageGenerator generator)
          Creates a new ImageWrapper object.
 
Method Summary
 java.lang.Object clone()
          Creates and returns a copy of this image.
 void crop(int x, int y, int w, int h)
          Crops the image.
 void dispose()
          Dispose the Graphics context and null out the image.
 void drawImage(ImageWrapper image, java.awt.geom.AffineTransform at)
          Draws another image to this image.
 void drawImage(ImageWrapper image, int x, int y)
          Draws another image to this image.
 void drawImage(java.lang.String filename, int x, int y)
          Draws another image to this image.
 void drawLine(int x1, int y1, int x2, int y2)
          Draws a line to this image from x1/y1 to x2/y2.
 void drawRect(int x, int y, int w, int h)
          Draws a rectangle to this image.
 void drawString(java.lang.String str, int x, int y)
          Draws a string to this image at the given coordinates.
 void fillRect(int x, int y, int w, int h)
          Draws a filled rectangle to this image.
 java.awt.image.BufferedImage getBufferedImage()
          Converts the internal image object to a BufferedImage (if it's not already) and returns it. this is necessary as not all images are of type BufferedImage. e.g. images loaded from a resource with the Toolkit are not.
 java.awt.Graphics2D getGraphics()
          Returns the Graphics object to directly paint to this Image.
 int getHeight()
          Returns the height of this image.
 java.awt.Image getImage()
          Returns the Image object represented by this ImageWrapper.
 int getPixel(int x, int y)
          Returns the pixel at x, y.
 java.awt.image.ImageProducer getSource()
          Returns the ImageProducer of the wrapped image
 int getWidth()
          Returns the width of this image.
 void reduceColors(int colors)
          Reduces the colors used in the image.
 void reduceColors(int colors, boolean dither)
          Reduces the colors used in the image.
 void reduceColors(int colors, boolean dither, boolean alphaToBitmask)
          Reduce the colors used in this image.
 void resize(int w, int h)
          Resize the image
protected  void resize(int w, int h, boolean smooth)
          resizes the image using the Graphics2D approach
 void resizeFast(int w, int h)
          Resize the image, using a fast and cheap algorithm
 void saveAs(java.io.OutputStream out, java.lang.String mimeType)
          Saves the image.
 void saveAs(java.io.OutputStream out, java.lang.String mimeType, float quality)
          Saves the image.
 void saveAs(java.io.OutputStream out, java.lang.String mimeType, float quality, boolean alpha)
          Saves the image.
 void saveAs(java.lang.String filename)
          Save the image.
 void saveAs(java.lang.String filename, float quality)
          Saves the image.
 void saveAs(java.lang.String filename, float quality, boolean alpha)
          Saves the image.
 void setColor(java.awt.Color color)
          Sets the color used to write/paint to this image.
 void setColor(int color)
          Sets the color used to write/paint to this image.
 void setColor(int red, int green, int blue)
          Sets the color used to write/paint to this image.
 void setColor(java.lang.String color)
          Sets the color used to write/paint to this image.
 void setFont(java.lang.String name, int style, int size)
          Set the font used to write on this image.
protected  void setImage(java.awt.Image img)
          Sets the internal image and clears the stored graphics object.
 void setTransparentPixel(int trans)
          Sets the palette index of the transparent color for Images with an IndexColorModel.
 void trim(int x, int y)
          Trims the image.
 void trim(int x, int y, boolean trimLeft, boolean trimTop, boolean trimRight, boolean trimBottom)
          Trims the image.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

image

protected java.awt.Image image

width

protected int width

height

protected int height

generator

protected ImageGenerator generator
Constructor Detail

ImageWrapper

public ImageWrapper(java.awt.Image image,
                    int width,
                    int height,
                    ImageGenerator generator)
Creates a new ImageWrapper object.

Parameters:
image - ...
width - ...
height - ...

ImageWrapper

public ImageWrapper(java.awt.Image image,
                    ImageGenerator generator)
Method Detail

getBufferedImage

public java.awt.image.BufferedImage getBufferedImage()
Converts the internal image object to a BufferedImage (if it's not already) and returns it. this is necessary as not all images are of type BufferedImage. e.g. images loaded from a resource with the Toolkit are not. By using getBufferedImage, images are only converted to a getBufferedImage when this is actually needed, which is better than storing images as BufferedImage in general.

Returns:
the Image object as a BufferedImage

getGraphics

public java.awt.Graphics2D getGraphics()
Returns the Graphics object to directly paint to this Image. Converts the internal image to a BufferedImage if necessary.

Returns:
the Graphics object for drawing into this image

setImage

protected void setImage(java.awt.Image img)
Sets the internal image and clears the stored graphics object. Any code that is changing the internal image should do it through this function to make sure getGraphcis() returns a valid graphics object the next time it is called.


clone

public java.lang.Object clone()
Creates and returns a copy of this image.

Overrides:
clone in class java.lang.Object
Returns:
a clone of this image.

getImage

public java.awt.Image getImage()
Returns the Image object represented by this ImageWrapper.

Returns:
the image object

getSource

public java.awt.image.ImageProducer getSource()
Returns the ImageProducer of the wrapped image

Returns:
the images's ImageProducer

dispose

public void dispose()
Dispose the Graphics context and null out the image.


setFont

public void setFont(java.lang.String name,
                    int style,
                    int size)
Set the font used to write on this image.


setColor

public void setColor(int red,
                     int green,
                     int blue)
Sets the color used to write/paint to this image.

Parameters:
red - ...
green - ...
blue - ...

setColor

public void setColor(int color)
Sets the color used to write/paint to this image.

Parameters:
color - ...

setColor

public void setColor(java.awt.Color color)
Sets the color used to write/paint to this image.

Parameters:
color - ...

setColor

public void setColor(java.lang.String color)
Sets the color used to write/paint to this image.

Parameters:
color - ...

drawString

public void drawString(java.lang.String str,
                       int x,
                       int y)
Draws a string to this image at the given coordinates.

Parameters:
str - ...
x - ...
y - ...

drawLine

public void drawLine(int x1,
                     int y1,
                     int x2,
                     int y2)
Draws a line to this image from x1/y1 to x2/y2.

Parameters:
x1 - ...
y1 - ...
x2 - ...
y2 - ...

drawRect

public void drawRect(int x,
                     int y,
                     int w,
                     int h)
Draws a rectangle to this image.

Parameters:
x - ...
y - ...
w - ...
h - ...

drawImage

public void drawImage(java.lang.String filename,
                      int x,
                      int y)
               throws java.io.IOException
Draws another image to this image.

Parameters:
filename - ...
x - ...
y - ...
Throws:
java.io.IOException

drawImage

public void drawImage(ImageWrapper image,
                      int x,
                      int y)
               throws java.io.IOException
Draws another image to this image.

Parameters:
image - ...
x - ...
y - ...
Throws:
java.io.IOException

drawImage

public void drawImage(ImageWrapper image,
                      java.awt.geom.AffineTransform at)
               throws java.io.IOException
Draws another image to this image.

Parameters:
image - ...
at - ...
Throws:
java.io.IOException

fillRect

public void fillRect(int x,
                     int y,
                     int w,
                     int h)
Draws a filled rectangle to this image.

Parameters:
x - ...
y - ...
w - ...
h - ...

getWidth

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

Returns:
the width of this image

getHeight

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

Returns:
the height of this image

crop

public void crop(int x,
                 int y,
                 int w,
                 int h)
Crops the image.

Parameters:
x - ...
y - ...
w - ...
h - ...

trim

public void trim(int x,
                 int y)
Trims the image.

Parameters:
x - the x-coordinate of the pixel specifying the background color
y - the y-coordinate of the pixel specifying the background color

trim

public void trim(int x,
                 int y,
                 boolean trimLeft,
                 boolean trimTop,
                 boolean trimRight,
                 boolean trimBottom)
Trims the image.

Parameters:
x -
y -
trimLeft -
trimTop -
trimRight -
trimBottom -

resize

protected void resize(int w,
                      int h,
                      boolean smooth)
resizes the image using the Graphics2D approach


resize

public void resize(int w,
                   int h)
Resize the image

Parameters:
w - ...
h - ...

resizeFast

public void resizeFast(int w,
                       int h)
Resize the image, using a fast and cheap algorithm

Parameters:
w - ...
h - ...

reduceColors

public void reduceColors(int colors)
Reduces the colors used in the image. Necessary before saving as GIF.

Parameters:
colors - colors the number of colors to use, usually <= 256.

reduceColors

public void reduceColors(int colors,
                         boolean dither)
Reduces the colors used in the image. Necessary before saving as GIF.

Parameters:
colors - colors the number of colors to use, usually <= 256.
dither - ...

reduceColors

public void reduceColors(int colors,
                         boolean dither,
                         boolean alphaToBitmask)
Reduce the colors used in this image. Useful and necessary before saving the image as GIF file.

Parameters:
colors - the number of colors to use, usually <= 256.
dither - ...
alphaToBitmask - ...

saveAs

public void saveAs(java.lang.String filename)
            throws java.io.IOException
Save the image. Image format is deduced from filename.

Parameters:
filename - ...
Throws:
java.io.IOException

saveAs

public void saveAs(java.lang.String filename,
                   float quality)
            throws java.io.IOException
Saves the image. Image format is deduced from filename.

Parameters:
filename - ...
quality - ...
Throws:
java.io.IOException

saveAs

public void saveAs(java.lang.String filename,
                   float quality,
                   boolean alpha)
            throws java.io.IOException
Saves the image. Image format is deduced from filename.

Parameters:
filename - ...
quality - ...
alpha - ...
Throws:
java.io.IOException

saveAs

public void saveAs(java.io.OutputStream out,
                   java.lang.String mimeType)
            throws java.io.IOException
Saves the image. Image format is deduced from mimeType.

Parameters:
out - ...
mimeType - ...
Throws:
java.io.IOException

saveAs

public void saveAs(java.io.OutputStream out,
                   java.lang.String mimeType,
                   float quality)
            throws java.io.IOException
Saves the image. Image format is deduced from mimeType.

Parameters:
out - ...
mimeType - ...
quality - ...
Throws:
java.io.IOException

saveAs

public void saveAs(java.io.OutputStream out,
                   java.lang.String mimeType,
                   float quality,
                   boolean alpha)
            throws java.io.IOException
Saves the image. Image format is deduced from mimeType.

Parameters:
out - ...
mimeType - ...
quality - ...
alpha - ...
Throws:
java.io.IOException

setTransparentPixel

public void setTransparentPixel(int trans)
Sets the palette index of the transparent color for Images with an IndexColorModel. This can be used together with getPixel(int, int).


getPixel

public int getPixel(int x,
                    int y)
Returns the pixel at x, y. If the image is indexed, it returns the palette index, otherwise the rgb code of the color is returned.

Parameters:
x - the x coordinate of the pixel
y - the y coordinate of the pixel
Returns:
the pixel at x, y


Copyright © 1998-1998-${year} Helma.org. All Rights Reserved.