Package helma.image
Class ImageWrapper
java.lang.Object
helma.image.ImageWrapper
Abstract base class for Image Wrappers.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionImageWrapper
(Image image, int width, int height, ImageGenerator generator) Creates a new ImageWrapper object.ImageWrapper
(Image image, ImageGenerator generator) -
Method Summary
Modifier and TypeMethodDescriptionclone()
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, int x, int y) Draws another image to this image.void
drawImage
(ImageWrapper image, AffineTransform at) Draws another image to this image.void
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
(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.Converts the internal image object to a BufferedImage (if it's not already) and returns it.Returns the Graphics object to directly paint to this Image.int
Returns the height of this image.getImage()
Returns the Image object represented by this ImageWrapper.int
getPixel
(int x, int y) Returns the pixel at x, y.Returns the ImageProducer of the wrapped imageint
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) Resizes the imageprotected void
resize
(int w, int h, boolean smooth) Resizes the image using the Graphics2D approachvoid
resizeFast
(int w, int h) Resize the image, using a fast and cheap algorithmvoid
saveAs
(OutputStream out, String mimeType) Saves the image.void
saveAs
(OutputStream out, String mimeType, float quality) Saves the image.void
saveAs
(OutputStream out, String mimeType, float quality, boolean alpha) Saves the image.void
Save the image.void
Saves the image.void
Saves the 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
Sets the color used to write/paint to this image.void
Sets the color used to write/paint to this image.void
Set the font used to write on this image.protected void
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.
-
Field Details
-
image
-
width
protected int width -
height
protected int height -
generator
-
-
Constructor Details
-
ImageWrapper
Creates a new ImageWrapper object.- Parameters:
image
- ...width
- ...height
- ...
-
ImageWrapper
-
-
Method Details
-
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
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
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
Creates and returns a copy of this image. -
getImage
Returns the Image object represented by this ImageWrapper.- Returns:
- the image object
-
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
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
Sets the color used to write/paint to this image.- Parameters:
color
- ...
-
setColor
Sets the color used to write/paint to this image.- Parameters:
color
- ...
-
drawString
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
Draws another image to this image.- Parameters:
filename
- ...x
- ...y
- ...- Throws:
IOException
-
drawImage
Draws another image to this image.- Parameters:
image
- ...x
- ...y
- ...- Throws:
IOException
-
drawImage
Draws another image to this image.- Parameters:
image
- ...at
- ...- Throws:
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 colory
- 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) Resizes 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
Save the image. Image format is deduced from filename.- Parameters:
filename
- ...- Throws:
IOException
-
saveAs
Saves the image. Image format is deduced from filename.- Parameters:
filename
- ...quality
- ...- Throws:
IOException
-
saveAs
Saves the image. Image format is deduced from filename.- Parameters:
filename
- ...quality
- ...alpha
- ...- Throws:
IOException
-
saveAs
Saves the image. Image format is deduced from mimeType.- Parameters:
out
- ...mimeType
- ...- Throws:
IOException
-
saveAs
Saves the image. Image format is deduced from mimeType.- Parameters:
out
- ...mimeType
- ...quality
- ...- Throws:
IOException
-
saveAs
public void saveAs(OutputStream out, String mimeType, float quality, boolean alpha) throws IOException Saves the image. Image format is deduced from mimeType.- Parameters:
out
- ...mimeType
- ...quality
- ...alpha
- ...- Throws:
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 withgetPixel(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 pixely
- the y coordinate of the pixel- Returns:
- the pixel at x, y
-