Package generic.util.image
Class ImageUtils
java.lang.Object
generic.util.image.ImageUtils
-
Method Summary
Modifier and TypeMethodDescriptionstatic Image
changeColor
(Image image, Color oldColor, Color newColor) Creates a new image that is the same as the given image but has the given colored pixels replaced with the given new colorstatic Image
createDisabledImage
(Image image, int brightnessPercent) Creates a disabled version of the given image.static BufferedImage
createEmptyImage
(int width, int height) Creates a new image of the given size.static Image
Creates an image of the given componentstatic Image
createScaledImage
(Image image, int width, int height, int hints) Creates a scaled image based upon the given image.static Image
Crops the given image, keeping the given boundsstatic BufferedImage
getBufferedImage
(Image image) Copies this image into a buffered image.static Icon
makeTransparent
(Icon icon) Make the specified icon semi-transparent using the default transparency alphastatic Icon
makeTransparent
(Icon icon, float alpha) Make the specified icon semi-transparent using the specified transparency alphastatic Image
Pads the given image with space in the amount given.static Image
placeImagesSideBySide
(Image left, Image right) Places the two given images side-by-side into a new image.static BufferedImage
Load an image from a filestatic RenderedImage
toRenderedImage
(Image image) Turns the given image into aRenderedImage
static boolean
waitForImage
(String imageName, Image image) Waits a reasonable amount of time for the given image to loadstatic void
writeFile
(RenderedImage i, File imageFile) Write the specified image to file in PNG formatstatic void
Write the specified image to file in PNG formatstatic void
writeIconToPNG
(Icon icon, String filename) Writes the given icon out to the file denoted byfilename
in the PNG format.
-
Method Details
-
createImage
Creates an image of the given component- Parameters:
c
- the component- Returns:
- the image
-
padImage
Pads the given image with space in the amount given.- Parameters:
i
- the image to padc
- the color to use for the padding backgroundtop
- the top paddingleft
- the left paddingright
- the right paddingbottom
- the bottom padding- Returns:
- a new image with the given image centered inside of padding
-
crop
Crops the given image, keeping the given bounds- Parameters:
i
- the image to cropbounds
- the new bounds- Returns:
- a new image based on the given image, cropped to the given bounds.
-
createEmptyImage
Creates a new image of the given size. This image is suitable for drawing operations.- Parameters:
width
- the width of the new imageheight
- the height of the new image- Returns:
- a new image of the given size. This image is suitable for drawing operations.
-
placeImagesSideBySide
Places the two given images side-by-side into a new image.- Parameters:
left
- the left imageright
- the right image- Returns:
- a new image with the two given images side-by-side into a new image.
-
toRenderedImage
Turns the given image into aRenderedImage
- Parameters:
image
- the image- Returns:
- the rendered image
-
getBufferedImage
Copies this image into a buffered image. If this image is already a buffered image, then it will be returned.- Parameters:
image
- the image- Returns:
- the buffered image
-
waitForImage
Waits a reasonable amount of time for the given image to load- Parameters:
imageName
- the name of the imageimage
- the image for which to wait- Returns:
- true if the wait was successful
-
writeFile
Write the specified image to file in PNG format- Parameters:
i
- the image to saveimageFile
- the file to save the image to- Throws:
IOException
- if there is an exception
-
writeFile
Write the specified image to file in PNG format- Parameters:
i
- the image to saveimageFile
- the file to save the image to- Throws:
IOException
- if there is an exception
-
readFile
Load an image from a file- Parameters:
imageFile
- image source-data file- Returns:
- the image, decoded from bytes in specified file
- Throws:
IOException
- if there is an exception
-
writeIconToPNG
Writes the given icon out to the file denoted byfilename
in the PNG format.- Parameters:
icon
- the icon to writefilename
- the filename denoting the write destination- Throws:
IOException
- seeImageIO.write(RenderedImage, String, File)
-
makeTransparent
Make the specified icon semi-transparent using the default transparency alpha- Parameters:
icon
- The icon to make semi-transparent- Returns:
- a new icon, based on the original, made semi-transparent
- See Also:
-
makeTransparent
Make the specified icon semi-transparent using the specified transparency alpha- Parameters:
icon
- the icon to make semi-transparentalpha
- the alpha value to use in making the icon transparent- Returns:
- a new icon, based on the original, made semi-transparent
-
createScaledImage
Creates a scaled image based upon the given image. NOTE: Avoid invocation by a static initializer.- Parameters:
image
- the image to scalewidth
- the new widthheight
- the new heighthints
-RenderingHints
used byGraphics2D
- Returns:
- a scaled version of the given image
-
createDisabledImage
Creates a disabled version of the given image. The disabled version will be grayed and have the varying gray levels blended together.- Parameters:
image
- the image to disablebrightnessPercent
- the amount of brightness to apply; 0-100- Returns:
- the new image
-
changeColor
Creates a new image that is the same as the given image but has the given colored pixels replaced with the given new color- Parameters:
image
- the image to changeoldColor
- the color to replacenewColor
- the color to use- Returns:
- the new image
-