Class BufferedImageUtils

java.lang.Object
org.carrot2.util.BufferedImageUtils

public class BufferedImageUtils extends Object
Various utility methods for working with BufferedImages.
  • Method Details

    • hasPartialTransparency

      public static boolean hasPartialTransparency(BufferedImage image)
      Returns true if the provided image has partially transparent areas (alpha channel).
      Parameters:
      image - the image
      Returns:
      true, if successful
    • hasTransparency

      public static boolean hasTransparency(BufferedImage image)
      Returns true if the provided image has any kind of transparent areas.
      Parameters:
      image - the image
      Returns:
      true, if successful
    • countDistinctColors

      public static int countDistinctColors(BufferedImage image)
      Returns the number of distinct colors (excluding transparency) in the image.
      Parameters:
      image - the image
      Returns:
      the int
    • getDistinctColors

      public static int[] getDistinctColors(BufferedImage image)
      Returns the image's distinct colors in an RGB format, discarding transparency information.
      Parameters:
      image - the image
      Returns:
      the distinct colors
    • getDistinctColors

      public static int[] getDistinctColors(BufferedImage image, int padding)
      Returns the image's distinct colors in an RGB format, discarding transparency information. Adds padding empty slots at the beginning of the returned array.
      Parameters:
      image - the image
      padding - the padding
      Returns:
      the distinct colors
    • getRgb

      public static int[][] getRgb(BufferedImage image)
      Returns a two dimensional array of the image's RGB values, including transparency.
      Parameters:
      image - the image
      Returns:
      the rgb
    • matte

      public static BufferedImage matte(BufferedImage source, Color matteColor)
      Performs matting of the source image using matteColor. Matting is rendering partial transparencies using solid color as if the original image was put on top of a bitmap filled with matteColor.
      Parameters:
      source - the source
      matteColor - the matte color
      Returns:
      the buffered image
    • drawImage

      public static void drawImage(BufferedImage image, BufferedImage canvas, int x, int y)
      Draws image on the canvas placing the top left corner of image at x / y offset from the top left corner of canvas.
      Parameters:
      image - the image
      canvas - the canvas
      x - the x
      y - the y