Package de.espirit.common.tools
Class Images
java.lang.Object
de.espirit.common.tools.Images
Generic utility to provide image related operations.
- Since:
- 5.2.21
-
Method Summary
Modifier and TypeMethodDescriptionstatic @NotNull BufferedImagefromByteArray(byte @NotNull [] bytes) Loads an image from the specified byte array and returns a buffered image.static @NotNull Imagestatic @NotNull BufferedImageLoads an image from the specified path and returns a buffered image.static BufferedImagefromStream(@Nullable InputStream stream) Loads an image from the specified input stream and returns a buffered image.static byte @NotNull []toByteArray(@NotNull BufferedImage image, @Nullable String type) Reads the specified image into an array of bytes.static @NotNull StringConverts the given byte array into a data URL of the formstatic @NotNull StringtoDataUrl(@NotNull BufferedImage image) Converts the given image into a data URL of the form
-
Method Details
-
fromByteArray
@NotNull public static @NotNull BufferedImage fromByteArray(byte @NotNull [] bytes) throws UncheckedIOException Loads an image from the specified byte array and returns a buffered image.- Parameters:
bytes- the input byte array to load the image from- Returns:
- the buffered image, never
null - Throws:
UncheckedIOException- if the image format is not supported- Since:
- 5.2.240504
-
fromIcon
- Parameters:
icon- the icon to convert, must not benull.- Returns:
- the converted image, never
null. - Since:
- 5.2.240504
-
fromStream
@Contract("!null -> !null; null -> null") public static BufferedImage fromStream(@Nullable @Nullable InputStream stream) Loads an image from the specified input stream and returns a buffered image.- Parameters:
stream- the input stream to load the image from- Returns:
- buffered image, or
nullis the stream isnull - Throws:
UncheckedIOException- if the image format is not supported- Since:
- 5.2.21
-
fromPath
Loads an image from the specified path and returns a buffered image.- Parameters:
path- the path to load the image from- Returns:
- the buffered image, never
null - Throws:
UncheckedIOException- if the image format is not supported- Since:
- 5.2.240504
-
toByteArray
public static byte @NotNull [] toByteArray(@NotNull @NotNull BufferedImage image, @Nullable @Nullable String type) throws UncheckedIOException Reads the specified image into an array of bytes.- Parameters:
image- The image to read, must not benull.type- The type of the image, e.g. "png". May benullif unknown.- Returns:
- The byte array containing the image, never
null - Throws:
UncheckedIOException- if the image could not be written- Since:
- 5.2.240504
-
toDataUrl
@NotNull public static @NotNull String toDataUrl(@NotNull @NotNull BufferedImage image) throws UncheckedIOException Converts the given image into a data URL of the form
data:mimetype;base64,<binary data>This URL can be used to embed images directly into a HTML page.
- Parameters:
image- the image to convert, must not benull- Returns:
- the data url containing the converted image encoded with base64, never
null - Throws:
UncheckedIOException- if the image could not be saved- Since:
- 5.2.240504
-
toDataUrl
@NotNull public static @NotNull String toDataUrl(byte @NotNull [] bytes, @NotNull @NotNull String mimeType) Converts the given byte array into a data URL of the form
data:mimetype;base64,<binary data>This URL can be used to embed images directly into a HTML page.
- Parameters:
bytes- the byte array containing the data to convert, must not benullmimeType- the mime-type, e.g. "image/png". Must not benull.- Returns:
- the data url containing the converted data encoded with base64, never
null - Since:
- 5.2.240504
-