Skip to main content

ImageRef API for the Kotlin Multiplatform Barcode Scanner SDK

ImageRef is a lightweight image reference type used throughout the Scanbot SDK to represent image data in a unified and efficient manner. Additionally, it acts as a universal interface for images that any component of the SDK captures, processes, or returns.

It enables memory-efficient image processing across the SDK and provides a consistent interface across all supported platforms in your Kotlin Multiplatform project.

For display, additional processing, or export, the ImageRef can be converted to platform-specific image types or encoded to byte arrays.

ImageRef creation

The KMP SDK provides two methods for creating ImageRef instances from different sources:

From file path

Create an ImageRef from an image file on the file system:

Create ImageRef from file path
loading...

The PathImageLoadOptions class allows you to configure how the image is loaded from the file path.

From encoded buffer

Create an ImageRef from an encoded image byte array (JPEG, PNG, etc.):

Create ImageRef from encoded buffer
loading...

The BufferImageLoadOptions class allows you to configure how the image is decoded from the buffer.

ImageRef usage

ImageRef is used throughout the SDK as an input source for image data. The SDK also uses ImageRef as the output for image crops in scanner results. In general, ImageRef behaves similarly to a bitmap, but it exists in a different memory space and is managed by the SDK.

caution

Please remember to dispose of large ImageRef objects, just as you would with Bitmaps. If not disposed, an unused ImageRef may remain in memory for some time before being released by the SDK.

Get image information

Retrieve metadata about the image, such as dimensions:

Get image information
loading...

Save image to file

Save an ImageRef to a file on the file system:

Save image to file
loading...

If encryption is enabled in the SDK, its parameters will be used to encrypt the file. You can also provide custom encryption options through SaveImageOptions.

Encode image to bytes

Convert an ImageRef to an encoded byte array:

Encode image to bytes
loading...

ImageRef is defined as an expect class in KMP, meaning it has platform-specific implementations for Android and iOS. The actual implementation leverages the native Scanbot SDKs on each platform, ensuring optimal performance and compatibility.

Want to scan longer than one minute?

Generate a free trial license to test the Scanbot SDK thoroughly.

Get free trial license