Package io.scanbot.sdk.image
Class ImageRef
- java.lang.Object
-
- io.scanbot.sdk.image.ImageRef
-
- All Implemented Interfaces:
java.lang.AutoCloseable
public class ImageRef extends java.lang.Object implements java.lang.AutoCloseableRepresent an image that is backed by native resources and can be created from various sources.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the native resources associated with the image.byte[]encodeImage(EncodeImageOptions options)Encodes the image with given options.protected voidfinalize()static ImageReffromEncodedBuffer(byte[] buffer, BufferImageLoadOptions options)Creates an image from the given encoded buffer e.g.static ImageReffromPath(java.lang.String path, PathImageLoadOptions options)Creates an image from the given path with given options.static ImageReffromStream(java.io.InputStream stream, BufferImageLoadOptions options)Creates an image from the given input stream with given options.java.util.UUIDgetUniqueId()Returns the unique identifier of the image native resource.ImageInfoimageInfo()Returns the image information.static voidreleaseAllImages()Releases all alive images despite any existing references.voidsaveImage(java.lang.String path, SaveImageOptions options)Saves the image to the given path with given options.
-
-
-
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:
closein interfacejava.lang.AutoCloseable
-
finalize
protected void finalize() throws java.lang.Throwable- Overrides:
finalizein classjava.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 fileoptions- 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 dataoptions- 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 bufferoptions- 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.IOExceptionSaves the image to the given path with given options.- Parameters:
path- path to save the image tooptions- options used during image saving- Throws:
InvalidImageRefException- if the image ref is invalidjava.io.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
-
-