Class ImageRef

java.lang.Object
io.scanbot.sdk.image.ImageRef
All Implemented Interfaces:
AutoCloseable

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

    • getUniqueId

      public 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 AutoCloseable
    • finalize

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

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

      public static ImageRef fromPath(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(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(String path, SaveImageOptions options) throws InvalidImageRefException, 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
      IOException - If an I/O error occurs while saving the image
    • encodeImage

      public byte[] encodeImage(EncodeImageOptions options) throws InvalidImageRefException
      Encodes the image with given options.
      Parameters:
      options - options used during image encoding
      Returns:
      encoded image buffer
      Throws:
      InvalidImageRefException - if the image could not be encoded
    • imageInfo

      public ImageInfo imageInfo() throws InvalidImageRefException
      Returns the image information.
      Returns:
      image information
      Throws:
      InvalidImageRefException - if the image information could not be retrieved