Class Images

java.lang.Object
de.espirit.common.tools.Images

public final class Images extends Object
Generic utility to provide image related operations.
Since:
5.2.21
  • 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

      @NotNull public static @NotNull Image fromIcon(@NotNull @NotNull Icon icon)
      Converts the given Icon into an Image.
      Parameters:
      icon - the icon to convert, must not be null.
      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 null is the stream is null
      Throws:
      UncheckedIOException - if the image format is not supported
      Since:
      5.2.21
    • fromPath

      @NotNull public static @NotNull BufferedImage fromPath(@NotNull @NotNull Path path)
      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 be null.
      type - The type of the image, e.g. "png". May be null if 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 be null
      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 be null
      mimeType - the mime-type, e.g. "image/png". Must not be null.
      Returns:
      the data url containing the converted data encoded with base64, never null
      Since:
      5.2.240504