Class ImageRef

  • All Implemented Interfaces:
    java.lang.AutoCloseable

    public class ImageRef
    extends java.lang.Object
    implements java.lang.AutoCloseable
    Represent an image that is backed by native resources and can be created from various sources.
    • Method Detail

      • getUniqueId

        public java.util.UUID getUniqueId()
        Returns the unique identifier of the image native resource.
        Returns:
        unique identifier
      • close

        public void close()
        Closes the native resources associated with the image. If not called explicitly, the resources will be released when the object is garbage collected.
        Specified by:
        close in interface java.lang.AutoCloseable
      • finalize

        protected void finalize()
                         throws java.lang.Throwable
        Overrides:
        finalize in class java.lang.Object
        Throws:
        java.lang.Throwable
      • releaseAllImages

        public static void releaseAllImages()
        Releases all alive images despite any existing references.
      • fromPath

        public static ImageRef fromPath​(java.lang.String path,
                                        PathImageLoadOptions options)
        Creates an image from the given path with given options.
        Parameters:
        path - path to the image file
        options - options used during image loading
        Returns:
        image reference or null if the image could not be loaded
      • fromStream

        public static ImageRef fromStream​(java.io.InputStream stream,
                                          BufferImageLoadOptions options)
        Creates an image from the given input stream with given options.
        Parameters:
        stream - stream that provides encoded (e.g. jpeg or png) image data
        options - options used during image loading
        Returns:
        image reference or null if the image could not be loaded
      • fromEncodedBuffer

        public static ImageRef fromEncodedBuffer​(byte[] buffer,
                                                 BufferImageLoadOptions options)
        Creates an image from the given encoded buffer e.g. from jpeg with given options.
        Parameters:
        buffer - encoded image buffer
        options - options used during image loading
        Returns:
        image reference or null if the image could not be loaded
      • saveImage

        public void saveImage​(java.lang.String path,
                              SaveImageOptions options)
                       throws InvalidImageRefException,
                              java.io.IOException
        Saves the image to the given path with given options.
        Parameters:
        path - path to save the image to
        options - options used during image saving
        Throws:
        InvalidImageRefException - if the image ref is invalid
        java.io.IOException - If an I/O error occurs while saving the image