Class ImageUtil


  • public final class ImageUtil
    extends Object
    Methods for working with Images
    • Method Detail

      • downloadImage

        public static BufferedImage downloadImage​(String url,
                                                  int connectTimeout,
                                                  int readTimeout)
                                           throws IOException
        Downloads an image
        Parameters:
        url - URL
        connectTimeout - Connection Timeout
        readTimeout - Read Timeout
        Returns:
        Downloaded Image or null if image could not be decoded
        Throws:
        MalformedURLException
        IOException
      • downloadImage

        public static BufferedImage downloadImage​(String url,
                                                  BufferedImage defaultImage,
                                                  int connectTimeout,
                                                  int readTimeout,
                                                  boolean logStackTrace)
        Downloads an image and returns the downloaded image or the default image in case of an error
        Parameters:
        url - URL
        defaultImage - Default Image which will be returned in case of an error
        connectTimeout - Connection Timeout
        readTimeout - Read Timeout
        logStackTrace - True if stack trace should be logged, false otherwise
        Returns:
        Downloaded image or the default image in case of an error
      • downloadImageRaw

        public static byte[] downloadImageRaw​(String url,
                                              int connectTimeout,
                                              int readTimeout)
                                       throws IOException
        Downloads an image
        Parameters:
        url - URL
        connectTimeout - Connection Timeout
        readTimeout - Read Timeout
        Returns:
        Downloaded Image data
        Throws:
        MalformedURLException
        IOException
      • generatePreviewImage

        public static BufferedImage generatePreviewImage​(Image img,
                                                         int width,
                                                         int height)
        Generates a preview for the given Image To preverse aspect ratio, you can set width to -1 and set height or the other way around
        Parameters:
        img - Original Image
        width - Width
        height - Height
        Returns:
        Scaled Image
      • generatePreviewImage

        public static BufferedImage generatePreviewImage​(Image img,
                                                         int width,
                                                         int height,
                                                         int hints)
        Generates a preview for the given Image To preverse aspect ratio, you can set width to -1 and set height or the other way around
        Parameters:
        img - Original Image
        width - Width
        height - Height
        hints - Hints
        Returns:
        Scaled Image
      • generatePreviewImage

        public static BufferedImage generatePreviewImage​(Image img,
                                                         int width,
                                                         int height,
                                                         int hints,
                                                         int type)
        Generates a preview for the given Image To preverse aspect ratio, you can set width to -1 and set height or the other way around
        Parameters:
        img - Original Image
        width - Width
        height - Height
        hints - Hints
        type - Image Type
        Returns:
        Scaled Image