# ImagePart


```
public final class ImagePart extends Part implements AutoCloseable
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [com.google.mlkit.genai.embedding.Part](https://developers.google.com/android/reference/com/google/mlkit/genai/embedding/Part) ||
|   | ↳ | [com.google.mlkit.genai.embedding.ImagePart](https://developers.google.com/android/reference/com/google/mlkit/genai/embedding/ImagePart) |

*** ** * ** ***

A class representing an image part of `https://developers.google.com/android/reference/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/com/google/mlkit/genai/embedding/ImagePart#close()` (or use `.use {}` / try-with-resources) to recycle `https://developers.google.com/android/reference/com/google/mlkit/genai/embedding/ImagePart#bitmap()` when finished, which is particularly useful when `https://developers.google.com/android/reference/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/com/google/mlkit/genai/embedding/ImagePart#ImagePart(android.graphics.Bitmap)(@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/android/graphics/Bitmap.html bitmap)` |
| `https://developers.google.com/android/reference/com/google/mlkit/genai/embedding/ImagePart#ImagePart(kotlin.ByteArray)(@https://developer.android.com/reference/androidx/annotation/NonNull.html byte[] blob)` Creates an `https://developers.google.com/android/reference/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/com/google/mlkit/genai/embedding/ImagePart#ImagePart(android.net.Uri)(@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/android/net/Uri.html uri)` Creates an `https://developers.google.com/android/reference/com/google/mlkit/genai/embedding/ImagePart` from a `https://developer.android.com/reference/android/net/Uri.html`. |

| ### Public methods |
|---|---|
| `void` | `https://developers.google.com/android/reference/com/google/mlkit/genai/embedding/ImagePart#close()()` Recycles the underlying `https://developers.google.com/android/reference/com/google/mlkit/genai/embedding/ImagePart#bitmap()` if it has not already been recycled. |
| `boolean` | `https://developers.google.com/android/reference/com/google/mlkit/genai/embedding/ImagePart#equals(kotlin.Any)(https://developer.android.com/reference/java/lang/Object.html other)` Compares this `https://developers.google.com/android/reference/com/google/mlkit/genai/embedding/ImagePart` to another object for equality. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/android/graphics/Bitmap.html` | `https://developers.google.com/android/reference/com/google/mlkit/genai/embedding/ImagePart#getBitmap()()` The `https://developer.android.com/reference/android/graphics/Bitmap.html` representation of the image. |
| `final int` | `https://developers.google.com/android/reference/com/google/mlkit/genai/embedding/ImagePart#getHeight()()` The height of the image in pixels. |
| `final int` | `https://developers.google.com/android/reference/com/google/mlkit/genai/embedding/ImagePart#getWidth()()` The width of the image in pixels. |
| `int` | `https://developers.google.com/android/reference/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/com/google/mlkit/genai/embedding/ImagePart#equals(kotlin.Any)` method. |
| `final boolean` | `https://developers.google.com/android/reference/com/google/mlkit/genai/embedding/ImagePart#getIsClosed()()` Returns whether this `https://developers.google.com/android/reference/com/google/mlkit/genai/embedding/ImagePart` has been closed and its underlying bitmap recycled. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developers.google.com/android/reference/com/google/mlkit/genai/embedding/ImagePart#toString()()` |

## Public constructors

### ImagePart

```
public ImagePart(@NonNull Bitmap bitmap)
```

### ImagePart

```
public ImagePart(@NonNull byte[] blob)
```

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

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull.html byte[] blob` | 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

```
public ImagePart(@NonNull Uri uri)
```

Creates an `https://developers.google.com/android/reference/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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/android/net/Uri.html uri` | 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 methods

### close

```
public void close()
```

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

### equals

```
public boolean equals(Object other)
```

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

| Returns |
|---|---|
| `boolean` | `true` if the other object is an `https://developers.google.com/android/reference/com/google/mlkit/genai/embedding/ImagePart` and references the same `https://developers.google.com/android/reference/com/google/mlkit/genai/embedding/ImagePart#bitmap()` instance. |

### getBitmap

```
public final @NonNull Bitmap getBitmap()
```

The `https://developer.android.com/reference/android/graphics/Bitmap.html` 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 `https://developers.google.com/android/reference/com/google/mlkit/genai/embedding/ImagePart#equals(kotlin.Any)` method.

### isClosed

```
public final boolean isClosed()
```

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

### toString

```
public @NonNull String toString()
```