Class ImageUtil
- java.lang.Object
-
- ch.supertomcat.supertomcatutils.image.ImageUtil
-
public final class ImageUtil extends Object
Methods for working with Images
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static BufferedImagedownloadImage(String url, int connectTimeout, int readTimeout)Downloads an imagestatic BufferedImagedownloadImage(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 errorstatic byte[]downloadImageRaw(String url, int connectTimeout, int readTimeout)Downloads an imagestatic BufferedImagegeneratePreviewImage(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 aroundstatic BufferedImagegeneratePreviewImage(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 aroundstatic BufferedImagegeneratePreviewImage(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
-
-
-
Method Detail
-
downloadImage
public static BufferedImage downloadImage(String url, int connectTimeout, int readTimeout) throws IOException
Downloads an image- Parameters:
url- URLconnectTimeout- Connection TimeoutreadTimeout- Read Timeout- Returns:
- Downloaded Image or null if image could not be decoded
- Throws:
MalformedURLExceptionIOException
-
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- URLdefaultImage- Default Image which will be returned in case of an errorconnectTimeout- Connection TimeoutreadTimeout- Read TimeoutlogStackTrace- 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- URLconnectTimeout- Connection TimeoutreadTimeout- Read Timeout- Returns:
- Downloaded Image data
- Throws:
MalformedURLExceptionIOException
-
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 Imagewidth- Widthheight- 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 Imagewidth- Widthheight- Heighthints- 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 Imagewidth- Widthheight- Heighthints- Hintstype- Image Type- Returns:
- Scaled Image
-
-