Package io.scanbot.sdk.image
Class ImageRef
java.lang.Object
io.scanbot.sdk.image.ImageRef
- All Implemented Interfaces:
AutoCloseable
Represent an image that is backed by native resources and can be created from various sources.
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()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(String path, PathImageLoadOptions options) Creates an image from the given path with given options.static ImageReffromStream(InputStream stream, BufferImageLoadOptions options) Creates an image from the given input stream with given options.Returns the unique identifier of the image native resource.Returns the image information.static voidReleases all alive images despite any existing references.voidsaveImage(String path, SaveImageOptions options) Saves the image to the given path with given options.
-
Method Details
-
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 interfaceAutoCloseable
-
finalize
-
releaseAllImages
public static void releaseAllImages()Releases all alive images despite any existing references. -
fromPath
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
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
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(String path, SaveImageOptions options) throws InvalidImageRefException, IOException Saves 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 invalidIOException- If an I/O error occurs while saving the image
-
encodeImage
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
Returns the image information.- Returns:
- image information
- Throws:
InvalidImageRefException- if the image information could not be retrieved
-