Class ImageUtils

java.lang.Object
generic.util.image.ImageUtils

public class ImageUtils extends Object
  • Method Details

    • createImage

      public static Image createImage(Component c)
      Creates an image of the given component
      Parameters:
      c - the component
      Returns:
      the image
    • padImage

      public static Image padImage(Image i, Color c, int top, int left, int right, int bottom)
      Pads the given image with space in the amount given.
      Parameters:
      i - the image to pad
      c - the color to use for the padding background
      top - the top padding
      left - the left padding
      right - the right padding
      bottom - the bottom padding
      Returns:
      a new image with the given image centered inside of padding
    • crop

      public static Image crop(Image i, Rectangle bounds)
      Crops the given image, keeping the given bounds
      Parameters:
      i - the image to crop
      bounds - the new bounds
      Returns:
      a new image based on the given image, cropped to the given bounds.
    • createEmptyImage

      public static BufferedImage createEmptyImage(int width, int height)
      Creates a new image of the given size. This image is suitable for drawing operations.
      Parameters:
      width - the width of the new image
      height - the height of the new image
      Returns:
      a new image of the given size. This image is suitable for drawing operations.
    • placeImagesSideBySide

      public static Image placeImagesSideBySide(Image left, Image right)
      Places the two given images side-by-side into a new image.
      Parameters:
      left - the left image
      right - the right image
      Returns:
      a new image with the two given images side-by-side into a new image.
    • toRenderedImage

      public static RenderedImage toRenderedImage(Image image)
      Turns the given image into a RenderedImage
      Parameters:
      image - the image
      Returns:
      the rendered image
    • getBufferedImage

      public static BufferedImage getBufferedImage(Image image)
      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

      public static boolean waitForImage(String imageName, Image image)
      Waits a reasonable amount of time for the given image to load
      Parameters:
      imageName - the name of the image
      image - the image for which to wait
      Returns:
      true if the wait was successful
    • writeFile

      public static void writeFile(Image i, File imageFile) throws IOException
      Write the specified image to file in PNG format
      Parameters:
      i - the image to save
      imageFile - the file to save the image to
      Throws:
      IOException - if there is an exception
    • writeFile

      public static void writeFile(RenderedImage i, File imageFile) throws IOException
      Write the specified image to file in PNG format
      Parameters:
      i - the image to save
      imageFile - the file to save the image to
      Throws:
      IOException - if there is an exception
    • readFile

      public static BufferedImage readFile(File imageFile) throws IOException
      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

      public static void writeIconToPNG(Icon icon, String filename) throws IOException
      Writes the given icon out to the file denoted by filename in the PNG format.
      Parameters:
      icon - the icon to write
      filename - the filename denoting the write destination
      Throws:
      IOException - see ImageIO.write(RenderedImage, String, File)
    • makeTransparent

      public static Icon makeTransparent(Icon icon)
      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:
      • DEFAULT_TRANSPARENCY_ALPHA
    • makeTransparent

      public static Icon makeTransparent(Icon icon, float alpha)
      Make the specified icon semi-transparent using the specified transparency alpha
      Parameters:
      icon - the icon to make semi-transparent
      alpha - the alpha value to use in making the icon transparent
      Returns:
      a new icon, based on the original, made semi-transparent
    • createScaledImage

      public static Image createScaledImage(Image image, int width, int height, int hints)
      Creates a scaled image based upon the given image. NOTE: Avoid invocation by a static initializer.
      Parameters:
      image - the image to scale
      width - the new width
      height - the new height
      hints - RenderingHints used by Graphics2D
      Returns:
      a scaled version of the given image
    • createDisabledImage

      public static Image createDisabledImage(Image image, int brightnessPercent)
      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 disable
      brightnessPercent - the amount of brightness to apply; 0-100
      Returns:
      the new image
    • changeColor

      public static 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 color
      Parameters:
      image - the image to change
      oldColor - the color to replace
      newColor - the color to use
      Returns:
      the new image