public final class ImageUtils extends Object
| Modifier and Type | Field and Description |
|---|---|
protected static Map<Icon,Icon> |
DISABLED_ICONS_CACHE
Disabled icons cache.
|
static List<String> |
SUPPORTED_IMAGES
Viewable image formats.
|
protected static Map<Icon,Map<Float,Icon>> |
TRANSPARENT_ICONS_CACHE
Transparent icons cache.
|
| Modifier and Type | Method and Description |
|---|---|
static BufferedImage |
copyToBufferedImage(BufferedImage bufferedImage)
Returns
BufferedImage containing a copy of BufferedImage. |
static BufferedImage |
copyToBufferedImage(Icon icon)
Returns
BufferedImage containing a copy of currently displayed Icon frame. |
static BufferedImage |
copyToBufferedImage(Image image)
Returns
BufferedImage containing a copy of Image. |
static BufferedImage |
createCompatibleImage(BufferedImage bufferedImage)
Returns new empty
BufferedImage compatible with default screen GraphicsConfiguration. |
static BufferedImage |
createCompatibleImage(int width,
int height)
Returns new
BufferedImage compatible with default screen GraphicsConfiguration. |
static BufferedImage |
createCompatibleImage(int width,
int height,
int transparency)
Returns new
BufferedImage compatible with default screen GraphicsConfiguration. |
static BufferedImage |
createDisabledCopy(BufferedImage bufferedImage)
Returns
BufferedImage that is copy of the specified BufferedImage made look disabled. |
static Icon |
createDisabledCopy(Icon icon)
|
static BufferedImage |
createDisabledCopy(Image image)
Returns
BufferedImage that is copy of the specified Image made look disabled. |
static BufferedImage |
createImageThumbnail(BufferedImage bufferedImage,
Dimension maxSize)
Returns thumbnail
BufferedImage of the specified BufferedImage. |
static BufferedImage |
createImageThumbnail(BufferedImage bufferedImage,
int maxSize)
Returns thumbnail
BufferedImage of the specified BufferedImage. |
static BufferedImage |
createImageThumbnail(BufferedImage bufferedImage,
int maxWidth,
int maxHeight)
Returns thumbnail
BufferedImage of the specified BufferedImage. |
static BufferedImage |
createInnerShadowImage(int width,
Shape shape,
int shadowWidth,
float opacity)
Returns shadow image based on provided shape.
|
static BufferedImage |
createShadowImage(int width,
int height,
Shape shape,
int shadowWidth,
float opacity,
boolean clip)
Returns shadow image based on provided shape.
|
static BufferedImage |
createTransparentCopy(BufferedImage bufferedImage,
float opacity)
Returns
BufferedImage that is copy of the specified BufferedImage made semi-transparent. |
static Icon |
createTransparentCopy(Icon icon,
float opacity)
|
static BufferedImage |
createTransparentCopy(Image image,
float opacity)
Returns
BufferedImage that is copy of the specified Image made semi-transparent. |
static BufferedImage |
cutImage(BufferedImage bufferedImage,
Shape shape)
Returns new
BufferedImage with the specified BufferedImage painted on it within the specified Shape. |
static BufferedImage |
cutImage(Icon icon,
Shape shape)
|
static BufferedImage |
cutImage(Image image,
Shape shape)
|
static BufferedImage |
decodeImage(String imageData)
Returns
BufferedImage decoded from Base64 string. |
static String |
encodeImage(BufferedImage image)
Returns image data encoded in Base64 string.
|
static Icon |
getDisabledCopy(Icon icon)
Returns new or cached copy of specified
Icon made look disabled. |
static Color |
getDominantColor(BufferedImage image)
Returns dominant
Color for the specified BufferedImage. |
static Icon |
getTransparentCopy(Icon icon,
float opacity)
Returns new or cached copy of specified
Icon made look disabled. |
static boolean |
isCompatibleImage(BufferedImage bufferedImage)
Returns whether or not specified
BufferedImage is compatible with default screen GraphicsConfiguration. |
static boolean |
isImageSupported(String name)
Returns whether or not loading of the image with extension mentioned in the specified name is supported.
|
static boolean |
isTransparent(BufferedImage bufferedImage,
int x,
int y)
Returns whether or not specified
BufferedImage pixel is fully transparent. |
static BufferedImage |
loadBufferedImage(InputStream inputStream)
Returns
BufferedImage loaded from the specified InputStream. |
static BufferedImage |
loadBufferedImage(Resource resource)
Returns
BufferedImage loaded from the specified Resource. |
static BufferedImage |
loadCompatibleImage(Resource resource)
Returns
BufferedImage loaded from the specified Resource. |
static ImageIcon |
loadImageIcon(InputStream inputStream)
|
static ImageIcon |
loadImageIcon(Resource resource)
|
static ImageIcon |
rotateIcon180(Icon icon)
|
static ImageIcon |
rotateIcon90CCW(Icon icon)
|
static ImageIcon |
rotateIcon90CW(Icon icon)
|
static BufferedImage |
rotateImage180(BufferedImage bufferedImage)
Returns new
BufferedImage with specified BufferedImage painted on it and rotated 180 degrees. |
static BufferedImage |
rotateImage180(Image image)
Returns new
BufferedImage with specified Image painted on it and rotated 180 degrees. |
static BufferedImage |
rotateImage90CCW(BufferedImage bufferedImage)
Returns new
BufferedImage with specified BufferedImage painted on it and rotated 90 degrees counter-clockwise. |
static BufferedImage |
rotateImage90CCW(Image image)
Returns new
BufferedImage with specified Image painted on it and rotated 90 degrees counter-clockwise. |
static BufferedImage |
rotateImage90CW(BufferedImage bufferedImage)
Returns new
BufferedImage with specified BufferedImage painted on it and rotated 90 degrees clockwise. |
static BufferedImage |
rotateImage90CW(Image image)
Returns new
BufferedImage with specified Image painted on it and rotated 90 degrees clockwise. |
static BufferedImage |
toBufferedImage(Icon icon)
Returns
BufferedImage converted from the specified Icon. |
static BufferedImage |
toBufferedImage(Image image)
Returns
BufferedImage converted from the specified Image. |
static BufferedImage |
toBufferedImage(RenderedImage renderedImage)
Returns
BufferedImage converted from the specified RenderedImage. |
static BufferedImage |
toCompatibleImage(BufferedImage bufferedImage)
Returns
BufferedImage compatible with default screen GraphicsConfiguration. |
static ImageIcon |
toImageIcon(Icon icon)
|
static ImageIcon |
toImageIcon(Image image)
|
static BufferedImage |
toNonNullBufferedImage(Icon icon)
Returns
BufferedImage converted from the specified Icon. |
static BufferedImage |
toNonNullBufferedImage(Image image)
Returns
BufferedImage converted from the specified Image. |
static BufferedImage |
toNonNullBufferedImage(RenderedImage renderedImage)
Returns
BufferedImage converted from the specified RenderedImage. |
static ImageIcon |
toNonNullImageIcon(Icon icon)
|
static ImageIcon |
toNonNullImageIcon(Image image)
|
protected static final Map<Icon,Icon> DISABLED_ICONS_CACHE
public static boolean isImageSupported(@Nullable String name)
name - image name with extension in ittrue if loading of the image with extension mentioned in the specified name is supported, false otherwisepublic static boolean isTransparent(@NotNull BufferedImage bufferedImage, int x, int y)
BufferedImage pixel is fully transparent.bufferedImage - BufferedImagex - BufferedImage pixel X indexy - BufferedImage pixel Y indextrue if specified BufferedImage pixel is fully transparent, false otherwise@NotNull public static BufferedImage createCompatibleImage(@NotNull BufferedImage bufferedImage)
BufferedImage compatible with default screen GraphicsConfiguration.bufferedImage - BufferedImage to use size and transparency settings fromBufferedImage compatible with default screen GraphicsConfiguration@NotNull public static BufferedImage createCompatibleImage(int width, int height)
BufferedImage compatible with default screen GraphicsConfiguration.width - BufferedImage widthheight - BufferedImage heightBufferedImage compatible with default screen GraphicsConfiguration@NotNull public static BufferedImage createCompatibleImage(int width, int height, int transparency)
BufferedImage compatible with default screen GraphicsConfiguration.width - new BufferedImage widthheight - new BufferedImage heighttransparency - new BufferedImage Transparency typeBufferedImage compatible with default screen GraphicsConfigurationpublic static boolean isCompatibleImage(@NotNull BufferedImage bufferedImage)
BufferedImage is compatible with default screen GraphicsConfiguration.bufferedImage - BufferedImage to checktrue if specified BufferedImage is compatible with default screen GraphicsConfiguration,
false otherwise@NotNull public static BufferedImage loadCompatibleImage(@NotNull Resource resource)
BufferedImage loaded from the specified Resource.
Resulting BufferedImage is also made compatible with default screen GraphicsConfiguration.resource - Resource to load BufferedImage fromBufferedImage loaded from the specified Resource@NotNull public static BufferedImage toCompatibleImage(@NotNull BufferedImage bufferedImage)
BufferedImage compatible with default screen GraphicsConfiguration.
Specified BufferedImage might be copied or simply returned "as is" as a result of calling this method.bufferedImage - BufferedImage to create copy of that will be compatible with default screen GraphicsConfigurationBufferedImage compatible with default screen GraphicsConfiguration.@NotNull public static BufferedImage loadBufferedImage(@NotNull Resource resource)
BufferedImage loaded from the specified Resource.resource - Resource to load BufferedImage fromBufferedImage loaded from the specified Resource@NotNull public static BufferedImage loadBufferedImage(@NotNull InputStream inputStream)
BufferedImage loaded from the specified InputStream.inputStream - InputStream to load BufferedImage fromBufferedImage loaded from the specified InputStream@Nullable public static BufferedImage toBufferedImage(@Nullable Image image)
BufferedImage converted from the specified Image.image - Image to convertBufferedImage converted from the specified Image@NotNull public static BufferedImage toNonNullBufferedImage(@NotNull Image image)
BufferedImage converted from the specified Image.image - Image to convertBufferedImage converted from the specified Image@Nullable public static BufferedImage toBufferedImage(@Nullable Icon icon)
BufferedImage converted from the specified Icon.icon - Icon to convertBufferedImage converted from the specified Icon@NotNull public static BufferedImage toNonNullBufferedImage(@NotNull Icon icon)
BufferedImage converted from the specified Icon.icon - Icon to convertBufferedImage converted from the specified Icon@Nullable public static BufferedImage toBufferedImage(@Nullable RenderedImage renderedImage)
BufferedImage converted from the specified RenderedImage.renderedImage - RenderedImage to convertBufferedImage converted from the specified RenderedImage@NotNull public static BufferedImage toNonNullBufferedImage(@NotNull RenderedImage renderedImage)
BufferedImage converted from the specified RenderedImage.renderedImage - RenderedImage to convertBufferedImage converted from the specified RenderedImage@NotNull public static BufferedImage copyToBufferedImage(@NotNull Icon icon)
BufferedImage containing a copy of currently displayed Icon frame.icon - Icon to create BufferedImage forBufferedImage containing a copy of currently displayed Icon frame@NotNull public static BufferedImage copyToBufferedImage(@NotNull Image image)
BufferedImage containing a copy of Image.image - Image to create BufferedImage forBufferedImage containing a copy of Image@NotNull public static BufferedImage copyToBufferedImage(@NotNull BufferedImage bufferedImage)
BufferedImage containing a copy of BufferedImage.bufferedImage - BufferedImage to create BufferedImage forBufferedImage containing a copy of BufferedImage@NotNull public static ImageIcon loadImageIcon(@NotNull Resource resource)
ImageIcon loaded from the specified Resource.
This method doesn't use ImageIO because loaded image might not be represented by a single BufferedImage.
For example GIF icons consist of many frames that are handled internally by ImageIcon.@NotNull public static ImageIcon loadImageIcon(@NotNull InputStream inputStream)
ImageIcon loaded from the specified Resource.
This method doesn't use ImageIO because loaded image might not be represented by a single BufferedImage.
For example GIF icons consist of many frames that are handled internally by ImageIcon.inputStream - InputStream to load ImageIcon fromImageIcon loaded from the specified Resource@NotNull public static Icon getDisabledCopy(@NotNull Icon icon)
Icon made look disabled.@NotNull public static BufferedImage createDisabledCopy(@NotNull Image image)
BufferedImage that is copy of the specified Image made look disabled.image - Image to create disabled copy forBufferedImage that is copy of the specified Image made look disabled@NotNull public static BufferedImage createDisabledCopy(@NotNull BufferedImage bufferedImage)
BufferedImage that is copy of the specified BufferedImage made look disabled.bufferedImage - BufferedImage to create disabled copy forBufferedImage that is copy of the specified BufferedImage made look disabled@NotNull public static Icon getTransparentCopy(@NotNull Icon icon, float opacity)
Icon made look disabled.@NotNull public static Icon createTransparentCopy(@NotNull Icon icon, float opacity)
@NotNull public static BufferedImage createTransparentCopy(@NotNull Image image, float opacity)
BufferedImage that is copy of the specified Image made semi-transparent.image - Image to create semi-transparent copy foropacity - opacity value, must be between 0 and 1BufferedImage that is copy of the specified Image made semi-transparent@NotNull public static BufferedImage createTransparentCopy(@NotNull BufferedImage bufferedImage, float opacity)
BufferedImage that is copy of the specified BufferedImage made semi-transparent.bufferedImage - BufferedImage to create semi-transparent copy foropacity - opacity value, must be between 0 and 1BufferedImage that is copy of the specified BufferedImage made semi-transparentpublic static BufferedImage cutImage(@NotNull Icon icon, @NotNull Shape shape)
icon - Icon to cutshape - Shape to cutBufferedImage with the specified Icon painted on it within the specified Shapepublic static BufferedImage cutImage(@NotNull Image image, @NotNull Shape shape)
image - Image to cutshape - Shape to cutBufferedImage with the specified Image painted on it within the specified Shapepublic static BufferedImage cutImage(@NotNull BufferedImage bufferedImage, @NotNull Shape shape)
BufferedImage with the specified BufferedImage painted on it within the specified Shape.bufferedImage - Image to cutshape - Shape to cutBufferedImage with the specified BufferedImage painted on it within the specified Shape@NotNull public static BufferedImage createImageThumbnail(@NotNull BufferedImage bufferedImage, @NotNull Dimension maxSize)
BufferedImage of the specified BufferedImage.
Note that this method can only scale specified BufferedImage down, it will not scale it up.
Also n that resulting BufferedImage will not have width and height larger than specified maximum ones, but might be less.bufferedImage - BufferedImage to create thumbnail formaxSize - maximum thumbnail BufferedImage sizeBufferedImage of the specified BufferedImage@NotNull public static BufferedImage createImageThumbnail(@NotNull BufferedImage bufferedImage, int maxWidth, int maxHeight)
BufferedImage of the specified BufferedImage.
Note that this method can only scale specified BufferedImage down, it will not scale it up.
Also n that resulting BufferedImage will not have width and height larger than specified maximum ones, but might be less.bufferedImage - BufferedImage to create thumbnail formaxWidth - maximum thumbnail BufferedImage widthmaxHeight - maximum thumbnail BufferedImage heightBufferedImage of the specified BufferedImage@NotNull public static BufferedImage createImageThumbnail(@NotNull BufferedImage bufferedImage, int maxSize)
BufferedImage of the specified BufferedImage.
Note that this method can only scale specified BufferedImage down, it will not scale it up.
Also note that resulting BufferedImage will not have width and height larger than specified maximum, but might be less.bufferedImage - BufferedImage to create thumbnail formaxSize - maximum thumbnail BufferedImage width and heightBufferedImage of the specified BufferedImage@NotNull public static Color getDominantColor(@NotNull BufferedImage image)
Color for the specified BufferedImage.image - BufferedImage to determine dominant Color forColor for the specified BufferedImage@NotNull public static BufferedImage rotateImage90CW(@NotNull Image image)
BufferedImage with specified Image painted on it and rotated 90 degrees clockwise.image - Image to rotateBufferedImage with specified Image painted on it and rotated 90 degrees clockwise.@NotNull public static BufferedImage rotateImage90CW(@NotNull BufferedImage bufferedImage)
BufferedImage with specified BufferedImage painted on it and rotated 90 degrees clockwise.bufferedImage - BufferedImage to rotateBufferedImage with specified BufferedImage painted on it and rotated 90 degrees clockwise.@NotNull public static BufferedImage rotateImage90CCW(@NotNull Image image)
BufferedImage with specified Image painted on it and rotated 90 degrees counter-clockwise.image - Image to rotateBufferedImage with specified Image painted on it and rotated 90 degrees counter-clockwise.@NotNull public static BufferedImage rotateImage90CCW(@NotNull BufferedImage bufferedImage)
BufferedImage with specified BufferedImage painted on it and rotated 90 degrees counter-clockwise.bufferedImage - BufferedImage to rotateBufferedImage with specified BufferedImage painted on it and rotated 90 degrees counter-clockwise.@NotNull public static BufferedImage rotateImage180(@NotNull Image image)
BufferedImage with specified Image painted on it and rotated 180 degrees.image - Image to rotateBufferedImage with specified Image painted on it and rotated 180 degrees.@NotNull public static BufferedImage rotateImage180(@NotNull BufferedImage bufferedImage)
BufferedImage with specified BufferedImage painted on it and rotated 180 degrees.bufferedImage - BufferedImage to rotateBufferedImage with specified BufferedImage painted on it and rotated 180 degrees.@NotNull public static BufferedImage createShadowImage(int width, int height, @NotNull Shape shape, int shadowWidth, float opacity, boolean clip)
width - shadow image widthheight - shadow image heightshape - shadow shapeshadowWidth - shadow widthopacity - shadow opacityclip - whether or not should clip shadow form@NotNull public static BufferedImage createInnerShadowImage(int width, @NotNull Shape shape, int shadowWidth, float opacity)
width - shadow image widthshape - shadow shapeshadowWidth - shadow widthopacity - shadow opacity@Nullable public static BufferedImage decodeImage(@Nullable String imageData)
BufferedImage decoded from Base64 string.imageData - image data decodeBufferedImage decoded from Base64 string@Nullable public static String encodeImage(@Nullable BufferedImage image)
image - image to encodeCopyright © 2020. All rights reserved.