# ImagePart


```
class ImagePart : Part, AutoCloseable
```

<br />

|---|---|---|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) |||
| ↳ | [com.google.mlkit.genai.embedding.Part](https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/Part) ||
|   | ↳ | [com.google.mlkit.genai.embedding.ImagePart](https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/ImagePart) |

*** ** * ** ***

A class representing an image part of `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/Content` for embedding. This class handles the conversion of various image sources into a `https://developer.android.com/reference/android/graphics/Bitmap.html` upon creation.

The `https://developer.android.com/reference/android/graphics/Bitmap.html` lifecycle is managed by the caller and is not recycled by the SDK during embedding generation. Callers may optionally call `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/ImagePart#close()` (or use `.use {}` / try-with-resources) to recycle `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/ImagePart#bitmap()` when finished, which is particularly useful when `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/ImagePart` decodes a new `https://developer.android.com/reference/android/graphics/Bitmap.html` via the `https://developer.android.com/reference/android/net/Uri.html` or `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html` constructors.

## Summary

| ### Public constructors |
|---|
| `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/ImagePart#ImagePart(android.graphics.Bitmap)(bitmap: https://developer.android.com/reference/android/graphics/Bitmap.html)` |
| `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/ImagePart#ImagePart(kotlin.ByteArray)(blob: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html)` Creates an `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/ImagePart` from a `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html`. |
| `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/ImagePart#ImagePart(android.net.Uri)(uri: https://developer.android.com/reference/android/net/Uri.html)` Creates an `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/ImagePart` from a `https://developer.android.com/reference/android/net/Uri.html`. |

| ### Public functions |
|---|---|
| `open https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/ImagePart#close()()` Recycles the underlying `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/ImagePart#bitmap()` if it has not already been recycled. |
| `open operator https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html` | `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/ImagePart#equals(kotlin.Any)(other: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html?)` Compares this `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/ImagePart` to another object for equality. |
| `open https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/ImagePart#hashCode()()` Returns a hash code value for the object, consistent with the overridden `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/ImagePart#equals(kotlin.Any)` method. |
| `open https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html` | `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/ImagePart#toString()()` |

| ### Public properties |
|---|---|
| `https://developer.android.com/reference/android/graphics/Bitmap.html` | `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/ImagePart#bitmap()` The `https://developer.android.com/reference/android/graphics/Bitmap.html` representation of the image. |
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/ImagePart#height()` The height of the image in pixels. |
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html` | `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/ImagePart#isClosed()` Returns whether this `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/ImagePart` has been closed and its underlying bitmap recycled. |
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/ImagePart#width()` The width of the image in pixels. |

## Public constructors

### ImagePart

```
ImagePart(bitmap: Bitmap)
```

### ImagePart

```
ImagePart(blob: ByteArray)
```

Creates an `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/ImagePart` from a `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html`.

| Parameters |
|---|---|
| `blob: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html` | the `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-byte-array/index.html` of the encoded image. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-illegal-argument-exception/index.html` | if the byte array cannot be decoded into a bitmap. |

### ImagePart

```
ImagePart(uri: Uri)
```

Creates an `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/ImagePart` from a `https://developer.android.com/reference/android/net/Uri.html`. This constructor will perform I/O to decode the image.

| Parameters |
|---|---|
| `uri: https://developer.android.com/reference/android/net/Uri.html` | the `https://developer.android.com/reference/android/net/Uri.html` pointing to the image. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | if the URI cannot be read. |
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-illegal-argument-exception/index.html` | if the data from the URI cannot be decoded into a bitmap. |

## Public functions

### close

```
open fun close(): Unit
```

Recycles the underlying `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/ImagePart#bitmap()` if it has not already been recycled.

### equals

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

Compares this `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/ImagePart` to another object for equality.

| Returns |
|---|---|
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html` | `true` if the other object is an `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/ImagePart` and references the same `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/ImagePart#bitmap()` instance. |

### hashCode

```
open fun hashCode(): Int
```

Returns a hash code value for the object, consistent with the overridden `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/ImagePart#equals(kotlin.Any)` method.

### toString

```
open fun toString(): String
```

## Public properties

### bitmap

```
val bitmap: Bitmap
```

The `https://developer.android.com/reference/android/graphics/Bitmap.html` representation of the image.

### height

```
val height: Int
```

The height of the image in pixels.

### isClosed

```
val isClosed: Boolean
```

Returns whether this `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/ImagePart` has been closed and its underlying bitmap recycled.

### width

```
val width: Int
```

The width of the image in pixels.