# InputImage

public class **InputImage** extends [Object](https://developer.android.com/reference/java/lang/Object.html)  
Represents an image object.

### Nested Class Summary

|---|---|---|---|
| @interface | [InputImage.ImageFormat](https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage.ImageFormat) || Accepted image format of vision APIs. |

### Constant Summary

|---|---|---|
| int | [IMAGE_FORMAT_NV21](https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage#IMAGE_FORMAT_NV21) | See `https://developer.android.com/reference/android/graphics/ImageFormat.html#NV21`. |
| int | [IMAGE_FORMAT_YUV_420_888](https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage#IMAGE_FORMAT_YUV_420_888) | See `https://developer.android.com/reference/android/graphics/ImageFormat.html#YUV_420_888`. |
| int | [IMAGE_FORMAT_YV12](https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage#IMAGE_FORMAT_YV12) | See `https://developer.android.com/reference/android/graphics/ImageFormat.html#YV12`. |

### Public Method Summary

|---|---|
| static [InputImage](https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage) | [fromBitmap](https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage#fromBitmap(android.graphics.Bitmap,%20int))([Bitmap](https://developer.android.com/reference/android/graphics/Bitmap.html) bitmap, int rotationDegrees) Creates an `https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage` from a `https://developer.android.com/reference/android/graphics/Bitmap.html`. |
| static [InputImage](https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage) | [fromByteArray](https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage#fromByteArray(byte[],%20int,%20int,%20int,%20int))(byte\[\] byteArray, int width, int height, int rotationDegrees, int format) Creates an `https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage` from a byte array, e.g., what you get from `https://developer.android.com/reference/android/hardware/Camera.html` callback. |
| static [InputImage](https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage) | [fromByteBuffer](https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage#fromByteBuffer(java.nio.ByteBuffer,%20int,%20int,%20int,%20int))([ByteBuffer](https://developer.android.com/reference/java/nio/ByteBuffer.html) byteBuffer, int width, int height, int rotationDegrees, int format) Creates an `https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage` from a `https://developer.android.com/reference/java/nio/ByteBuffer.html`. |
| static [InputImage](https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage) | [fromFilePath](https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage#fromFilePath(android.content.Context,%20android.net.Uri))([Context](https://developer.android.com/reference/android/content/Context.html) context, [Uri](https://developer.android.com/reference/android/net/Uri.html) imageUri) Creates an `https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage` from a local image file Uri. |
| static [InputImage](https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage) | [fromMediaImage](https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage#fromMediaImage(android.media.Image,%20int))([Image](https://developer.android.com/reference/android/media/Image.html) image, int rotationDegrees) Creates an `https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage` from an `https://developer.android.com/reference/android/media/Image.html` object, e.g., what you obtained from [android.hardware.camera2 API](https://developer.android.com/reference/android/hardware/camera2/package-summary). |

### Inherited Method Summary

From class java.lang.Object

|---|---|
| [Object](https://developer.android.com/reference/java/lang/Object.html) | clone() |
| boolean | equals([Object](https://developer.android.com/reference/java/lang/Object.html) arg0) |
| void | finalize() |
| final [Class](https://developer.android.com/reference/java/lang/Class.html)\<?\> | getClass() |
| int | hashCode() |
| final void | notify() |
| final void | notifyAll() |
| [String](https://developer.android.com/reference/java/lang/String.html) | toString() |
| final void | wait(long arg0, int arg1) |
| final void | wait(long arg0) |
| final void | wait() |

## Constants

#### public static final int
**IMAGE_FORMAT_NV21**

See `https://developer.android.com/reference/android/graphics/ImageFormat.html#NV21`.
Constant Value: 17

#### public static final int
**IMAGE_FORMAT_YUV_420_888**

See `https://developer.android.com/reference/android/graphics/ImageFormat.html#YUV_420_888`.
Constant Value: 35

#### public static final int
**IMAGE_FORMAT_YV12**

See `https://developer.android.com/reference/android/graphics/ImageFormat.html#YV12`.
Constant Value: 842094169

## Public Methods

#### public static [InputImage](https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage)
**fromBitmap** ([Bitmap](https://developer.android.com/reference/android/graphics/Bitmap.html) bitmap, int rotationDegrees)

Creates an `https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage`
from a `https://developer.android.com/reference/android/graphics/Bitmap.html`.

##### Parameters

| bitmap | the input `https://developer.android.com/reference/android/graphics/Bitmap.html`. |
| rotationDegrees | the image's counter-clockwise orientation degrees. Only 0, 90, 180, 270 are supported. IllegalArgumentException will be thrown if the input degree is not in the list. |
|---|---|

#### public static [InputImage](https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage)
**fromByteArray** (byte\[\] byteArray, int width, int height, int rotationDegrees, int format)

Creates an `https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage`
from a byte array, e.g., what you get from `https://developer.android.com/reference/android/hardware/Camera.html`
callback.

##### Parameters

| byteArray | the content of the image |
| width | the width of the image |
| height | the height of the image |
| rotationDegrees | the image's counter-clockwise orientation degrees. Only 0, 90, 180, 270 are supported. IllegalArgumentException will be thrown if the input degree is not in the list. |
| format | the image format. The supported formats are `https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage#IMAGE_FORMAT_NV21` and `https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage#IMAGE_FORMAT_YV12`. For IMAGE_FORMAT_YUV_420_888, please use `https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage#fromMediaImage(android.media.Image,%20int)`. |
|---|---|

#### public static [InputImage](https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage)
**fromByteBuffer** ([ByteBuffer](https://developer.android.com/reference/java/nio/ByteBuffer.html) byteBuffer, int width, int height, int rotationDegrees, int format)

Creates an `https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage`
from a `https://developer.android.com/reference/java/nio/ByteBuffer.html`.

We assume the entire buffer from position zero to its limit is all image data.

##### Parameters

| byteBuffer | the content of the image |
| width | the width of the image |
| height | the height of the image |
| rotationDegrees | the image's counter-clockwise orientation degrees. Only 0, 90, 180, 270 are supported. IllegalArgumentException will be thrown if the input degree is not in the list. |
| format | the image format. The supported formats are `https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage#IMAGE_FORMAT_NV21` and `https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage#IMAGE_FORMAT_YV12`. For IMAGE_FORMAT_YUV_420_888, please use `https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage#fromMediaImage(android.media.Image,%20int)`. |
|---|---|

#### public static [InputImage](https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage)
**fromFilePath** ([Context](https://developer.android.com/reference/android/content/Context.html) context, [Uri](https://developer.android.com/reference/android/net/Uri.html) imageUri)

Creates an `https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage`
from a local image file Uri.

##### Throws

| [IOException](https://developer.android.com/reference/java/io/IOException.html) | if the image could not be retrieved from the specified imageUri. This could happen even if the Uri came from content chooser, e.g., some users might have content providers for remote resources. |
|---|---|

#### public static [InputImage](https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage)
**fromMediaImage** ([Image](https://developer.android.com/reference/android/media/Image.html) image, int rotationDegrees)

Creates an `https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage`
from an `https://developer.android.com/reference/android/media/Image.html`
object, e.g., what you obtained from [android.hardware.camera2
API](https://developer.android.com/reference/android/hardware/camera2/package-summary).

Please wait for the detector to finish processing this `https://developers.google.com/android/reference/com/google/mlkit/vision/common/InputImage`
before you close the underlying `https://developer.android.com/reference/android/media/Image.html`.

##### Parameters

| image | the android.media.Image, where only JPEG / YUV_420_888 formats are supported at this moment and YUV_420_888 is more efficient for all our APIs. |
| rotationDegrees | the image's counter-clockwise orientation degrees. Only 0, 90, 180, 270 are supported. IllegalArgumentException will be thrown if the input degree is not in the list. |
|---|---|