ImagePart

public final class ImagePart extends Part


A data class representing an image part of a prompt. This class handles the conversion of various image sources into a Bitmap upon creation.

Note: Equality is determined by the content of the bitmap (sameAs), not by reference.

Summary

Public constructors

ImagePart(@NonNull byte[] blob)

Creates an ImagePart from a ByteArray.

Creates an ImagePart from a Uri.

Public methods

boolean
equals(Object other)

Compares this ImagePart to another object for equality.

final @NonNull Bitmap

the internal Bitmap representation of the image.

final int

the height of the image in pixels.

final int

the width of the image in pixels.

int

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

Public constructors

ImagePart

public ImagePart(@NonNull Bitmap bitmap)

ImagePart

public ImagePart(@NonNull byte[] blob)

Creates an ImagePart from a ByteArray.

Parameters
@NonNull byte[] blob

the ByteArray of the encoded image.

Throws
java.lang.IllegalArgumentException

if the byte array cannot be decoded into a bitmap.

ImagePart

public ImagePart(@NonNull Uri uri)

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

Parameters
@NonNull Uri uri

the Uri pointing to the image.

Throws
java.io.IOException

if the URI cannot be read.

java.lang.IllegalArgumentException

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

Public methods

equals

public boolean equals(Object other)

Compares this ImagePart to another object for equality.

Returns
boolean

true if the other object is an ImagePart and their bitmaps have the same dimensions, configuration, and pixel data.

getBitmap

public final @NonNull Bitmap getBitmap()

the internal Bitmap representation of the image.

getHeight

public final int getHeight()

the height of the image in pixels.

getWidth

public final int getWidth()

the width of the image in pixels.

hashCode

public int hashCode()

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