public static final class ImageWriter.Builder
extends Object



Builder class for ImageWriter objects.

Summary

Public constructors

Builder(Surface surface)

Constructs a new builder for ImageWriter.

Public methods

ImageWriter build()

Builds a new ImageWriter object.

ImageWriter.Builder setDataSpace(int dataSpace)

Set the dataspace of this ImageWriter.

ImageWriter.Builder setHardwareBufferFormat(int hardwareBufferFormat)

Set the hardwareBuffer format of this ImageWriter.

ImageWriter.Builder setImageFormat(int imageFormat)

Set the image format of this ImageWriter.

ImageWriter.Builder setMaxImages(int maxImages)

Set the maximum number of images.

ImageWriter.Builder setUsage(long usage)

Set the usage flag of this ImageWriter.

ImageWriter.Builder setWidthAndHeight(int width, int height)

Set the width and height of images.

Inherited methods

From class java.lang.Object

Object clone()

Creates and returns a copy of this object.

boolean equals(Object obj)

Indicates whether some other object is "equal to" this one.

void finalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

final Class<?> getClass()

Returns the runtime class of this Object.

int hashCode()

Returns a hash code value for the object.

final void notify()

Wakes up a single thread that is waiting on this object's monitor.

final void notifyAll()

Wakes up all threads that are waiting on this object's monitor.

String toString()

Returns a string representation of the object.

final void wait(long timeoutMillis, int nanos)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait(long timeoutMillis)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait()

Causes the current thread to wait until it is awakened, typically by being notified or interrupted.

Public constructors

Builder

public Builder (Surface surface)

Constructs a new builder for ImageWriter.

Parameters
surface Surface: The destination Surface this writer produces Image data into.
This value cannot be null.
Throws
IllegalArgumentException if the surface is already abandoned.

Public methods

build

public ImageWriter build ()

Builds a new ImageWriter object.

Returns
ImageWriter The new ImageWriter object.
This value cannot be null.

setMaxImages

public ImageWriter.Builder setMaxImages (int maxImages)

Set the maximum number of images. Default value is 1.

Parameters
maxImages int: The maximum number of Images the user will want to access simultaneously for producing Image data.
Value is 1 or greater
Returns
ImageWriter.Builder the Builder instance with customized usage value.
This value cannot be null.

setWidthAndHeight

public ImageWriter.Builder setWidthAndHeight (int width, 
                int height)

Set the width and height of images. Default size is dependent on the Surface that is provided by the downstream end-point.

Parameters
width int: The width in pixels that will be passed to the producer.
Value is 1 or greater
height int: The height in pixels that will be passed to the producer.
Value is 1 or greater
Returns
ImageWriter.Builder the Builder instance with customized width and height.
This value cannot be null.

Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Last updated 2026-02-26 UTC.