ImageWriterCompat

public final class ImageWriterCompat


Helper for accessing features of ImageWriter in a backwards compatible fashion.

Summary

Public methods

static @NonNull ImageWriter
newInstance(
    @NonNull Surface surface,
    @IntRange(from = "1") @NonNull int maxImages,
    @NonNull int format
)

Create a new ImageWriter with given number of max Images and format.

Public methods

newInstance

@NonNull
public static ImageWriter newInstance(
    @NonNull Surface surface,
    @IntRange(from = "1") @NonNull int maxImages,
    @NonNull int format
)

Create a new ImageWriter with given number of max Images and format.

The {@code maxImages} parameter determines the maximum number of android.media.Image objects that can be be dequeued from the {@code ImageWriter} simultaneously. Requesting more buffers will use up more memory, so it is important to use only the minimum number necessary.

The format specifies the image format of this ImageWriter. The format from the {@code surface} will be overridden with this format. For example, if the surface is obtained from a android.graphics.SurfaceTexture, the default format may be RGBA_8888. If the application creates an ImageWriter with this surface and PRIVATE, this ImageWriter will be able to operate with PRIVATE Images.

Note that the consumer end-point may or may not be able to support Images with different format, for such case, the application should only use this method if the consumer is able to consume such images.

The input Image size depends on the Surface that is provided by the downstream consumer end-point.

Parameters
@NonNull Surface surface

The destination Surface this writer produces Image data into.

@IntRange(from = "1") @NonNull int maxImages

The maximum number of Images the user will want to access simultaneously for producing Image data. This should be as small as possible to limit memory use. Once maxImages Images are dequeued by the user, one of them has to be queued back before a new Image can be dequeued for access via dequeueInputImage.

@NonNull int format

The format of this ImageWriter. It can be any valid format specified by android.graphics.ImageFormat or android.graphics.PixelFormat.

Returns
ImageWriter

a new ImageWriter instance.