ImagePart

class ImagePart : Part, AutoCloseable


A class representing an image part of Content for embedding. This class handles the conversion of various image sources into a Bitmap upon creation.

The Bitmap lifecycle is managed by the caller and is not recycled by the SDK during embedding generation. Callers may optionally call close (or use .use {} / try-with-resources) to recycle bitmap when finished, which is particularly useful when ImagePart decodes a new Bitmap via the Uri or ByteArray constructors.

Summary

Public constructors

ImagePart(bitmap: Bitmap)

Creates an ImagePart from a ByteArray.

ImagePart(uri: Uri)

Creates an ImagePart from a Uri.

Public functions

open Unit

Recycles the underlying bitmap if it has not already been recycled.

open operator Boolean
equals(other: Any?)

Compares this ImagePart to another object for equality.

open Int

Returns a hash code value for the object, consistent with the overridden equals method.

open String

Public properties

Bitmap

The Bitmap representation of the image.

Int

The height of the image in pixels.

Boolean

Returns whether this ImagePart has been closed and its underlying bitmap recycled.

Int

The width of the image in pixels.

Public constructors

ImagePart

ImagePart(bitmap: Bitmap)

ImagePart

ImagePart(blob: ByteArray)

Creates an ImagePart from a ByteArray.

Parameters
blob: ByteArray

the ByteArray of the encoded image.

Throws
IllegalArgumentException

if the byte array cannot be decoded into a bitmap.

ImagePart

ImagePart(uri: Uri)

Creates an ImagePart from a Uri. This constructor will perform I/O to decode the image.

Parameters
uri: Uri

the Uri pointing to the image.

Throws
IOException

if the URI cannot be read.

IllegalArgumentException

if the data from the URI cannot be decoded into a bitmap.

Public functions

close

open fun close(): Unit

Recycles the underlying bitmap if it has not already been recycled.

equals

open operator fun equals(other: Any?): Boolean

Compares this ImagePart to another object for equality.

Returns
Boolean

true if the other object is an ImagePart and references the same bitmap instance.

hashCode

open fun hashCode(): Int

Returns a hash code value for the object, consistent with the overridden equals method.

toString

open fun toString(): String

Public properties

bitmap

val bitmap: Bitmap

The Bitmap representation of the image.

height

val height: Int

The height of the image in pixels.

isClosed

val isClosed: Boolean

Returns whether this ImagePart has been closed and its underlying bitmap recycled.

width

val width: Int

The width of the image in pixels.