Package jexer.bits

Class ImageUtils


  • public class ImageUtils
    extends java.lang.Object
    ImageUtils contains methods to: - Check if an image is fully transparent. - Scale an image and preserve aspect ratio. - Open an animated image as an Animation. - Compute the distance between two colors in RGB space. - Compute the partial movement between two colors in RGB space.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  ImageUtils.Scale
      Selections for fitting the image to the text cells.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.awt.image.BufferedImage createImage​(java.awt.image.BufferedImage image, int width, int height)
      Create a BufferedImage using the same color model as another image.
      static Animation getAnimation​(java.io.File file)
      Open an image as an Animation.
      static Animation getAnimation​(java.io.InputStream inputStream)
      Open an image as an Animation.
      static Animation getAnimation​(java.lang.String filename)
      Open an image as an Animation.
      static Animation getAnimation​(java.net.URL url)
      Open an image as an Animation.
      static boolean isFullyOpaque​(java.awt.image.BufferedImage image)
      Check if any pixels in an image have not-100% alpha value.
      static boolean isFullyTransparent​(java.awt.image.BufferedImage image)
      Check if any pixels in an image have not-0% alpha value.
      static int rgbDistance​(int first, int second)
      Report the absolute distance in RGB space between two RGB colors.
      static int rgbMove​(int start, int end, double fraction)
      Move from one point in RGB space to another, by a certain fraction.
      static java.awt.image.BufferedImage scaleImage​(java.awt.image.BufferedImage image, int width, int height, ImageUtils.Scale scale, java.awt.Color backColor)
      Scale an image to be scaleFactor size and/or stretch it to fit a target box.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • isFullyTransparent

        public static boolean isFullyTransparent​(java.awt.image.BufferedImage image)
        Check if any pixels in an image have not-0% alpha value.
        Parameters:
        image - the image to check
        Returns:
        true if every pixel is fully transparent
      • isFullyOpaque

        public static boolean isFullyOpaque​(java.awt.image.BufferedImage image)
        Check if any pixels in an image have not-100% alpha value.
        Parameters:
        image - the image to check
        Returns:
        true if every pixel is fully transparent
      • scaleImage

        public static java.awt.image.BufferedImage scaleImage​(java.awt.image.BufferedImage image,
                                                              int width,
                                                              int height,
                                                              ImageUtils.Scale scale,
                                                              java.awt.Color backColor)
        Scale an image to be scaleFactor size and/or stretch it to fit a target box.
        Parameters:
        image - the image to scale
        width - the width in pixels for the destination image
        height - the height in pixels for the destination image
        scale - the scaling type
        backColor - the background color to use for Scale.SCALE
        Returns:
        the scaled image
      • getAnimation

        public static Animation getAnimation​(java.lang.String filename)
        Open an image as an Animation.
        Parameters:
        filename - the name of the file that contains an animation
        Returns:
        the animation, or null on error
      • getAnimation

        public static Animation getAnimation​(java.io.File file)
        Open an image as an Animation.
        Parameters:
        file - the file that contains an animation
        Returns:
        the animation, or null on error
      • getAnimation

        public static Animation getAnimation​(java.net.URL url)
        Open an image as an Animation.
        Parameters:
        url - the URK that contains an animation
        Returns:
        the animation, or null on error
      • getAnimation

        public static Animation getAnimation​(java.io.InputStream inputStream)
        Open an image as an Animation.
        Parameters:
        inputStream - the inputStream that contains an animation
        Returns:
        the animation, or null on error
      • rgbDistance

        public static int rgbDistance​(int first,
                                      int second)
        Report the absolute distance in RGB space between two RGB colors.
        Parameters:
        first - the first color
        second - the second color
        Returns:
        the distance
      • rgbMove

        public static int rgbMove​(int start,
                                  int end,
                                  double fraction)
        Move from one point in RGB space to another, by a certain fraction.
        Parameters:
        start - the starting point color
        end - the ending point color
        fraction - the amount of movement between start and end, between 0.0 (start) and 1.0 (end).
        Returns:
        the final color
      • createImage

        public static java.awt.image.BufferedImage createImage​(java.awt.image.BufferedImage image,
                                                               int width,
                                                               int height)
        Create a BufferedImage using the same color model as another image.
        Parameters:
        image - the original image
        width - the width of the new image
        height - the height of the new image
        Returns:
        the new image