# ImagePart


```
public final class ImagePart extends Part
```

<br />

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

*** ** * ** ***

A data class representing an image part of a prompt. This class handles the conversion of various image sources into a `https://developer.android.com/reference/android/graphics/Bitmap.html` upon creation.

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

## Summary

| ### Public constructors |
|---|
| `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/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/prompt/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/prompt/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/prompt/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/prompt/ImagePart` from a `https://developer.android.com/reference/android/net/Uri.html`. |

| ### Public methods |
|---|---|
| `boolean` | `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/ImagePart#equals(kotlin.Any)(https://developer.android.com/reference/java/lang/Object.html other)` Compares this 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/prompt/ImagePart#getBitmap()()` the internal `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/prompt/ImagePart#getHeight()()` the height of the image in pixels. |
| `final int` | `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/ImagePart#getWidth()()` the width of the image in pixels. |
| `int` | `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/ImagePart#hashCode()()` 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 `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/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/prompt/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

### 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 `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 `equals` method.