ImageWriter.Builder


public static final class ImageWriter.Builder
extends Object

java.lang.Object
   ↳ android.media.ImageWriter.Builder


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

Public constructors

Builder

Added in API level 33
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

Added in API level 33
public ImageWriter build ()

Builds a new ImageWriter object.

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

setDataSpace

Added in API level 33
public ImageWriter.Builder setDataSpace (int dataSpace)

Set the dataspace of this ImageWriter. The default value is DataSpace.DATASPACE_UNKNOWN.

Parameters
dataSpace int: The dataspace of the image that this writer will produce. Value is either 0 or a combination of DataSpace.DATASPACE_DEPTH, DataSpace.DATASPACE_DYNAMIC_DEPTH, DataSpace.DATASPACE_HEIF, android.hardware.DataSpace.DATASPACE_HEIF_ULTRAHDR, DataSpace.DATASPACE_JPEG_R, DataSpace.DATASPACE_UNKNOWN, DataSpace.DATASPACE_SCRGB_LINEAR, DataSpace.DATASPACE_SRGB, DataSpace.DATASPACE_SCRGB, DataSpace.DATASPACE_DISPLAY_P3, DataSpace.DATASPACE_BT2020_HLG, DataSpace.DATASPACE_BT2020_PQ, DataSpace.DATASPACE_ADOBE_RGB, DataSpace.DATASPACE_JFIF, DataSpace.DATASPACE_BT601_625, DataSpace.DATASPACE_BT601_525, DataSpace.DATASPACE_BT2020, DataSpace.DATASPACE_BT709, DataSpace.DATASPACE_DCI_P3, DataSpace.DATASPACE_SRGB_LINEAR, and android.hardware.DataSpace.DATASPACE_DISPLAY_BT2020

Returns
ImageWriter.Builder the builder instance with customized dataspace value. This value cannot be null.

setHardwareBufferFormat

Added in API level 33
public ImageWriter.Builder setHardwareBufferFormat (int hardwareBufferFormat)

Set the hardwareBuffer format of this ImageWriter. The default value is HardwareBuffer.RGBA_8888.

This function works together with setDataSpace(int) for an ImageWriter instance. Setting at least one of these two replaces setImageFormat(int) function.

Parameters
hardwareBufferFormat int: The HardwareBuffer format of the image that this writer will produce. Value is HardwareBuffer.RGBA_8888, HardwareBuffer.RGBA_FP16, HardwareBuffer.RGBA_1010102, HardwareBuffer.RGBX_8888, HardwareBuffer.RGB_888, HardwareBuffer.RGB_565, HardwareBuffer.BLOB, HardwareBuffer.YCBCR_420_888, HardwareBuffer.D_16, HardwareBuffer.D_24, HardwareBuffer.DS_24UI8, HardwareBuffer.D_FP32, HardwareBuffer.DS_FP32UI8, HardwareBuffer.S_UI8, HardwareBuffer.YCBCR_P010, HardwareBuffer.YCBCR_P210, HardwareBuffer.R_8, HardwareBuffer.R_16, HardwareBuffer.RG_1616, or HardwareBuffer.RGBA_10101010

Returns
ImageWriter.Builder the Builder instance with customized buffer format. This value cannot be null.

setImageFormat

Added in API level 33
public ImageWriter.Builder setImageFormat (int imageFormat)

Set the image format of this ImageWriter. Default format depends on the Surface provided.

Parameters
imageFormat int: The format of the ImageWriter. It can be any valid specified by ImageFormat or PixelFormat. Value is ImageFormat.UNKNOWN, PixelFormat.RGBA_8888, PixelFormat.RGBX_8888, PixelFormat.RGB_888, ImageFormat.RGB_565, ImageFormat.YV12, ImageFormat.Y8, android.graphics.ImageFormat.Y16, ImageFormat.YCBCR_P010, ImageFormat.YCBCR_P210, ImageFormat.NV16, ImageFormat.NV21, ImageFormat.YUY2, ImageFormat.JPEG, ImageFormat.DEPTH_JPEG, ImageFormat.YUV_420_888, ImageFormat.YUV_422_888, ImageFormat.YUV_444_888, ImageFormat.FLEX_RGB_888, ImageFormat.FLEX_RGBA_8888, ImageFormat.RAW_SENSOR, ImageFormat.RAW_PRIVATE, ImageFormat.RAW10, ImageFormat.RAW12, ImageFormat.DEPTH16, ImageFormat.DEPTH_POINT_CLOUD, android.graphics.ImageFormat.RAW_DEPTH, android.graphics.ImageFormat.RAW_DEPTH10, ImageFormat.PRIVATE, ImageFormat.HEIC, android.graphics.ImageFormat.HEIC_ULTRAHDR, or ImageFormat.JPEG_R

Returns
ImageWriter.Builder the Builder instance with customized image format. This value cannot be null.

Throws
IllegalArgumentException if imageFormat is invalid.

setMaxImages

Added in API level 33
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.

setUsage

Added in API level 33
public ImageWriter.Builder setUsage (long usage)

Set the usage flag of this ImageWriter.

If this function is not called, usage bit will be set to HardwareBuffer.USAGE_CPU_WRITE_OFTEN if the image format is not PRIVATE.

Parameters
usage long: The intended usage of the images produced by this ImageWriter. Value is either 0 or a combination of HardwareBuffer.USAGE_CPU_READ_RARELY, HardwareBuffer.USAGE_CPU_READ_OFTEN, HardwareBuffer.USAGE_CPU_WRITE_RARELY, HardwareBuffer.USAGE_CPU_WRITE_OFTEN, HardwareBuffer.USAGE_GPU_SAMPLED_IMAGE, HardwareBuffer.USAGE_GPU_COLOR_OUTPUT, HardwareBuffer.USAGE_COMPOSER_OVERLAY, HardwareBuffer.USAGE_PROTECTED_CONTENT, HardwareBuffer.USAGE_VIDEO_ENCODE, HardwareBuffer.USAGE_GPU_DATA_BUFFER, HardwareBuffer.USAGE_SENSOR_DIRECT_DATA, HardwareBuffer.USAGE_GPU_CUBE_MAP, HardwareBuffer.USAGE_GPU_MIPMAP_COMPLETE, and HardwareBuffer.USAGE_FRONT_BUFFER

Returns
ImageWriter.Builder the Builder instance with customized usage flag. This value cannot be null.

setWidthAndHeight

Added in API level 33
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.