# ImagePart

# 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.md.txt) ||
|   | ↳ | [com.google.mlkit.genai.prompt.ImagePart](https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/ImagePart.md.txt) |

*** ** * ** ***

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 Bitmap bitmap)` |
| `ImagePart(@NonNull byte[] blob)` Creates an `ImagePart` from a `ByteArray`. |
| `ImagePart(@NonNull Uri uri)` Creates an `ImagePart` from a `Uri`. |

| ### Public methods |
|---|---|
| `boolean` | `equals(Object other)` Compares this ImagePart to another object for equality. |
| `final @NonNull Bitmap` | `getBitmap()` the internal `Bitmap` representation of the image. |
| `final int` | `getHeight()` the height of the image in pixels. |
| `final int` | `getWidth()` the width of the image in pixels. |
| `int` | `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 `ImagePart` from a `ByteArray`.

| Parameters |
|---|---|
| `@NonNull byte[] blob` | the `ByteArray` of the encoded image. |

| Throws |
|---|---|
| `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 |
|---|---|
| `IOException` | if the URI cannot be read. |
| `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.