Package net.sf.freecol.common.util
Class ImageUtils
- java.lang.Object
-
- net.sf.freecol.common.util.ImageUtils
-
public class ImageUtils extends java.lang.ObjectCollection of static image manipulation utilities. Only generic routines belong here, anything specific to FreeCol belongs in ImageLibrary or ImageResource.
-
-
Constructor Summary
Constructors Constructor Description ImageUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.awt.image.BufferedImagecreateBufferedImage(java.awt.Image image)Creates a buffered image from an inputImage.static java.awt.image.BufferedImagecreateCenteredImage(java.awt.image.BufferedImage image, int width, int height)Creates a new image of the given size with the provided image centered.static java.awt.image.BufferedImagecreateCenteredImage(java.awt.image.BufferedImage image, java.awt.Dimension size)Creates a new image of the given size with the provided image centered.static java.awt.image.BufferedImagecreateGrayscaleImage(java.awt.Image image)Create a grayscale buffered image version of an inputImage.static java.awt.image.BufferedImagecreateHalvedImage(java.awt.Image image)Create a buffered image that is roughly half the size in both dimensions of an inputImage.static java.awt.image.BufferedImagecreateMirroredImage(java.awt.Image image)Create a buffered image that mirrors an inputImage.static java.awt.image.BufferedImagecreateResizedImage(java.awt.Image image, int width, int height)Create a buffered image resized from a plainImage.static java.awt.image.BufferedImagecreateResizedImage(java.awt.Image image, int width, int height, boolean interpolation)Create a buffered image resized from a plainImage.static voiddrawTiledImage(java.awt.image.BufferedImage image, java.awt.Graphics g, javax.swing.JComponent c, java.awt.Insets insets)Draw a (usually small) background image into a (usually larger) space specified by a component, tiling the image to fill up the space.static java.awt.image.BufferedImagefadeImage(java.awt.Image img, float fade, float target)Create a faded version of an image.static voidfillTexture(java.awt.Graphics2D g2d, java.awt.image.BufferedImage img, int x, int y, int width, int height)Fill a rectangle with a texture image.static java.awt.image.BufferedImageimageWithAlphaFromMask(java.awt.image.BufferedImage image, java.awt.image.BufferedImage mask)Returns the result where the given mask has been applied to the given image.static java.awt.DimensionwildcardDimension(java.awt.Dimension d, java.awt.Dimension nominal)Given a dimension with potential wildcard (non-positive) parts, and a nominal dimension, use the nominal dimension to remove any wildcard parts.
-
-
-
Method Detail
-
createBufferedImage
public static java.awt.image.BufferedImage createBufferedImage(java.awt.Image image)
Creates a buffered image from an inputImage.- Parameters:
image- TheImage.- Returns:
- The new
BufferedImage.
-
createGrayscaleImage
public static java.awt.image.BufferedImage createGrayscaleImage(java.awt.Image image)
Create a grayscale buffered image version of an inputImage.- Parameters:
image- TheImage.- Returns:
- The new halved
BufferedImage.
-
createHalvedImage
public static java.awt.image.BufferedImage createHalvedImage(java.awt.Image image)
Create a buffered image that is roughly half the size in both dimensions of an inputImage. Note: perhaps this should be createQuarteredImage?- Parameters:
image- TheImage.- Returns:
- The new halved
BufferedImage.
-
createMirroredImage
public static java.awt.image.BufferedImage createMirroredImage(java.awt.Image image)
Create a buffered image that mirrors an inputImage.- Parameters:
image- TheImageobject.- Returns:
- The new mirrored
BufferedImageobject.
-
createResizedImage
public static java.awt.image.BufferedImage createResizedImage(java.awt.Image image, int width, int height)Create a buffered image resized from a plainImage. Note that while the result will fit in width x height, it tends to retain its original aspect ratio.- Parameters:
image- TheImageobject.width- The desired width.height- The desired height.- Returns:
- The new resized
BufferedImageobject.
-
createResizedImage
public static java.awt.image.BufferedImage createResizedImage(java.awt.Image image, int width, int height, boolean interpolation)Create a buffered image resized from a plainImage. Note that while the result will fit in width x height, it tends to retain its original aspect ratio.- Parameters:
image- TheImageobject.width- The desired width.height- The desired height.interpolation- Use interpolation while resizing.- Returns:
- The new resized
BufferedImageobject.
-
drawTiledImage
public static void drawTiledImage(java.awt.image.BufferedImage image, java.awt.Graphics g, javax.swing.JComponent c, java.awt.Insets insets)Draw a (usually small) background image into a (usually larger) space specified by a component, tiling the image to fill up the space.- Parameters:
image- ABufferedImageto tile with (null fills with background color).g- TheGraphicsto draw to.c- TheJComponentthat defines the space.insets- OptionalInsetsto apply.
-
fillTexture
public static void fillTexture(java.awt.Graphics2D g2d, java.awt.image.BufferedImage img, int x, int y, int width, int height)Fill a rectangle with a texture image.- Parameters:
g2d- TheGraphics2Dused for painting the border.img- TheBufferedImageto fill the texture.x- The x-component of the offset to start filling at.y- The y-component of the offset to start filling at.width- The width of the rectangle.height- The height of the rectangle.
-
createCenteredImage
public static java.awt.image.BufferedImage createCenteredImage(java.awt.image.BufferedImage image, java.awt.Dimension size)Creates a new image of the given size with the provided image centered.- Parameters:
image- The image to be drawn in the center (both vertically and horizontally) of the new image.size- The size of the new image.- Returns:
- A new image.
-
createCenteredImage
public static java.awt.image.BufferedImage createCenteredImage(java.awt.image.BufferedImage image, int width, int height)Creates a new image of the given size with the provided image centered.- Parameters:
image- The image to be drawn in the center (both vertically and horizontally) of the new image.width- The width of the new image.height- The height of the new image.- Returns:
- A new image.
-
wildcardDimension
public static java.awt.Dimension wildcardDimension(java.awt.Dimension d, java.awt.Dimension nominal)Given a dimension with potential wildcard (non-positive) parts, and a nominal dimension, use the nominal dimension to remove any wildcard parts.- Parameters:
d- TheDimensionto consider.nominal- The nominalDimension.- Returns:
- The conformning wildcard-free
Dimension.
-
fadeImage
public static java.awt.image.BufferedImage fadeImage(java.awt.Image img, float fade, float target)Create a faded version of an image.- Parameters:
img- TheImageto fade.fade- The amount of fading.target- The offset.- Returns:
- The faded image.
-
imageWithAlphaFromMask
public static java.awt.image.BufferedImage imageWithAlphaFromMask(java.awt.image.BufferedImage image, java.awt.image.BufferedImage mask)Returns the result where the given mask has been applied to the given image.- Parameters:
image- The image.mask- The mask. Only the alpha channel from the mask is used.- Returns:
- An image with the opacity from the mask.
-
-