Summary: Ctors | Methods | Inherited Methods | [Expand All]
public static class

# Frame.Builder

extends Object

java.lang.Object
↳ | com.google.android.gms.vision.Frame.Builder

## Class Overview

Builder for creating a frame instance. At a minimum, image information must be specified either through `setBitmap(Bitmap)` or `setImageData(ByteBuffer, int, int, int)`.

## Summary

Public Constructors
| Frame.Builder()

Public Methods
Frame | build() Creates the frame instance.
Frame.Builder | setBitmap(Bitmap image) Sets the image data for the frame from a supplied bitmap.
Frame.Builder | setId(int id) Sets the frame ID.
Frame.Builder | setImageData(ByteBuffer data, int width, int height, int format) Sets the image data from the supplied byte buffer, size, and format.
Frame.Builder | setRotation(int rotation) Sets the image rotation, indicating the rotation from the upright orientation.
Frame.Builder | setTimestampMillis(long timestampMillis) Sets the frame timestamp, in milliseconds.

[Expand] Inherited Methods
From class java.lang.Object
Object | clone()
boolean | equals(Object arg0)
void | finalize()
final Class<?> | getClass()
int | hashCode()
final void | notify()
final void | notifyAll()
String | toString()
final void | wait(long arg0, int arg1)
final void | wait(long arg0)
final void | wait()

## Public Constructors

#### public Frame.Builder ()

## Public Methods

#### public Frame build ()

Creates the frame instance.

##### Throws

IllegalStateException | if the image data has not been set via `setBitmap(Bitmap)` or `setImageData(ByteBuffer, int, int, int)`.

#### public Frame.Builder setBitmap (Bitmap image)

Sets the image data for the frame from a supplied bitmap.

While this is a convenient way to specify certain images (e.g., images read from a file), note that a copy is required to extract pixel information for use in detectors -- this could mean extra GC overhead. Using `setImageData(ByteBuffer, int, int, int)` is the preferred way to specify image data if you can handle the data in a supported byte format and reuse the byte buffer, since it does not require a making a copy.

#### public Frame.Builder setId (int id)

Sets the frame ID. A frame source such as a live video camera or a video player is expected to assign IDs in monotonically increasing order, to indicate the sequence that the frame appeared relative to other frames.

A `Detector.Processor` implementation may rely upon this sequence ID to detect frame sequence gaps, to compute velocity, etc.

#### public Frame.Builder setImageData (ByteBuffer data, int width, int height, int format)

Sets the image data from the supplied byte buffer, size, and format.

##### Parameters

data | contains image byte data according to the associated format.
format | one of `NV16`, `NV21`, or `YV12`.

##### Throws

IllegalArgumentException | if the supplied data is null, or an invalid image format was supplied.

#### public Frame.Builder setRotation (int rotation)

Sets the image rotation, indicating the rotation from the upright orientation.

Since the camera may deliver images that are rotated (e.g., if the user holds the device upside down), specifying the rotation with the image indicates how to make the image be upright, if necessary. Some detectors may rely upon rotating the image before attempting detection, whereas others may not. In preserving the original image from the camera along with this value, the detector may choose whether to make this correction (and to assume the associated cost).

However, note that the detector is expected to report detection position coordinates that are relative to the upright version of the image (whether or not the image was actually rotated by the detector). The `Detector` will always deliver frame metadata to the `Detector.Processor` that indicates the dimensions and orientation of an unrotated, upright frame.

##### Parameters

rotation | one of `ROTATION_0`, `ROTATION_90`, `ROTATION_180`, `ROTATION_270`. Has the same meaning as `getRotation()`.

#### public Frame.Builder setTimestampMillis (long timestampMillis)

Sets the frame timestamp, in milliseconds. A frame source such as a live video camera or a video player is expected to assign timestamps in a way that makes sense for the medium. For example, live video may use the capture time of each frame, whereas a video player may use the elapsed time to the frame within the video. Timestamps should be in monotonically increasing order, to indicate the passage of time.

A `Detector.Processor` implementation may rely upon this sequence ID to detect frame sequence gaps, to compute velocity, etc.