Class ImageUtils


  • public class ImageUtils
    extends Object
    Image utility methods
    Author:
    osbornb
    • Constructor Detail

      • ImageUtils

        public ImageUtils()
    • Method Detail

      • createBufferedImage

        public static BufferedImage createBufferedImage​(int width,
                                                        int height,
                                                        String imageFormat)
        Create a buffered image for the dimensions and image format
        Parameters:
        width - image width
        height - image height
        imageFormat - image format
        Returns:
        image
      • isFullyTransparent

        public static boolean isFullyTransparent​(BufferedImage image)
        Check if the image is fully transparent, meaning it contains only transparent pixels as an empty image
        Parameters:
        image - image
        Returns:
        true if fully transparent
      • isTransparent

        public static boolean isTransparent​(BufferedImage image,
                                            int x,
                                            int y)
        Check if the pixel in the image at the x and y is transparent
        Parameters:
        image - image
        x - x location
        y - y location
        Returns:
        true if transparent
      • getImage

        public static BufferedImage getImage​(byte[] imageBytes)
                                      throws IOException
        Get a buffered image of the image bytes
        Parameters:
        imageBytes - image bytes
        Returns:
        buffered image or null
        Throws:
        IOException - upon failure
        Since:
        1.1.2
      • writeImageToBytes

        public static byte[] writeImageToBytes​(BufferedImage image,
                                               String formatName,
                                               Float quality)
                                        throws IOException
        Write the image to bytes in the provided format and optional quality
        Parameters:
        image - buffered image
        formatName - image format name
        quality - null or quality between 0.0 and 1.0
        Returns:
        image bytes
        Throws:
        IOException - upon failure
        Since:
        1.1.2
      • writeImageToBytes

        public static byte[] writeImageToBytes​(BufferedImage image,
                                               String formatName)
                                        throws IOException
        Write the image to bytes in the provided format
        Parameters:
        image - buffered image
        formatName - image format name
        Returns:
        image bytes
        Throws:
        IOException - upon failure
        Since:
        1.1.2
      • compressAndWriteImageToBytes

        public static byte[] compressAndWriteImageToBytes​(BufferedImage image,
                                                          String formatName,
                                                          float quality)
        Compress and write the image to bytes in the provided format and quality
        Parameters:
        image - buffered image
        formatName - image format name
        quality - quality between 0.0 and 1.0
        Returns:
        compressed image bytes
        Since:
        1.1.2
      • closeQuietly

        public static void closeQuietly​(Closeable closeable)
        Close quietly
        Parameters:
        closeable - closeable
        Since:
        1.1.2