HeifWriter.Builder


public final class HeifWriter.Builder


Builder class for constructing a HeifWriter object from specified parameters.

Summary

Public constructors

Builder(
    @NonNull FileDescriptor fd,
    @IntRange(from = 1) int width,
    @IntRange(from = 1) int height,
    int inputMode
)

Construct a Builder with output specified by its file descriptor.

Builder(
    @NonNull String path,
    @IntRange(from = 1) int width,
    @IntRange(from = 1) int height,
    int inputMode
)

Construct a Builder with output specified by its path.

Public methods

@NonNull HeifWriter

Build a HeifWriter object.

@NonNull HeifWriter.Builder
setGridEnabled(boolean gridEnabled)

Set whether to enable grid option.

@NonNull HeifWriter.Builder

Provide a handler for the HeifWriter to use.

@NonNull HeifWriter.Builder
setMaxImages(@IntRange(from = 1) int maxImages)

Set the maximum number of images to write.

@NonNull HeifWriter.Builder
setPrimaryIndex(@IntRange(from = 0) int primaryIndex)

Set the primary image index.

@NonNull HeifWriter.Builder
setQuality(@IntRange(from = 0, to = 100) int quality)

Set the quality for encoding images.

@NonNull HeifWriter.Builder
setRotation(@IntRange(from = 0) int rotation)

Set the image rotation in degrees.

Public constructors

Builder

Added in 1.0.0
public Builder(
    @NonNull FileDescriptor fd,
    @IntRange(from = 1) int width,
    @IntRange(from = 1) int height,
    int inputMode
)

Construct a Builder with output specified by its file descriptor.

Parameters
@NonNull FileDescriptor fd

File descriptor of the file to be written.

@IntRange(from = 1) int width

Width of the image in number of pixels.

@IntRange(from = 1) int height

Height of the image in number of pixels.

int inputMode

Input mode for this writer, must be one of INPUT_MODE_BUFFER, INPUT_MODE_SURFACE, or INPUT_MODE_BITMAP.

Builder

Added in 1.0.0
public Builder(
    @NonNull String path,
    @IntRange(from = 1) int width,
    @IntRange(from = 1) int height,
    int inputMode
)

Construct a Builder with output specified by its path.

Parameters
@NonNull String path

Path of the file to be written.

@IntRange(from = 1) int width

Width of the image in number of pixels.

@IntRange(from = 1) int height

Height of the image in number of pixels.

int inputMode

Input mode for this writer, must be one of INPUT_MODE_BUFFER, INPUT_MODE_SURFACE, or INPUT_MODE_BITMAP.

Public methods

build

Added in 1.0.0
public @NonNull HeifWriter build()

Build a HeifWriter object.

Returns
@NonNull HeifWriter

a HeifWriter object built according to the specifications.

Throws
java.io.IOException

if failed to create the writer, possibly due to failure to create android.media.MediaMuxer or android.media.MediaCodec.

setGridEnabled

Added in 1.0.0
public @NonNull HeifWriter.Builder setGridEnabled(boolean gridEnabled)

Set whether to enable grid option.

Parameters
boolean gridEnabled

Whether to enable grid option. If enabled, the tile size will be automatically chosen. Default is to enable.

Returns
@NonNull HeifWriter.Builder

this Builder object.

setHandler

Added in 1.0.0
public @NonNull HeifWriter.Builder setHandler(@Nullable Handler handler)

Provide a handler for the HeifWriter to use.

Parameters
@Nullable Handler handler

If not null, client will receive all callbacks on the handler's looper. Otherwise, client will receive callbacks on a looper created by the writer. Default is null.

Returns
@NonNull HeifWriter.Builder

this Builder object.

setMaxImages

Added in 1.0.0
public @NonNull HeifWriter.Builder setMaxImages(@IntRange(from = 1) int maxImages)

Set the maximum number of images to write.

Parameters
@IntRange(from = 1) int maxImages

Max number of images to write. Frames exceeding this number will not be written to file. The writing can be stopped earlier before this number of images are written by stop, except for the input mode of INPUT_MODE_SURFACE, where the EOS timestamp must be specified (via setInputEndOfStreamTimestamp and reached. Default is 1.

Returns
@NonNull HeifWriter.Builder

this Builder object.

setPrimaryIndex

Added in 1.0.0
public @NonNull HeifWriter.Builder setPrimaryIndex(@IntRange(from = 0) int primaryIndex)

Set the primary image index.

Parameters
@IntRange(from = 0) int primaryIndex

Index of the image that should be marked as primary, must be within range [0, maxImages - 1] inclusive. Default is 0.

Returns
@NonNull HeifWriter.Builder

this Builder object.

setQuality

Added in 1.0.0
public @NonNull HeifWriter.Builder setQuality(@IntRange(from = 0, to = 100) int quality)

Set the quality for encoding images.

Parameters
@IntRange(from = 0, to = 100) int quality

A number between 0 and 100 (inclusive), with 100 indicating the best quality supported by this implementation. Default is 100.

Returns
@NonNull HeifWriter.Builder

this Builder object.

setRotation

Added in 1.0.0
public @NonNull HeifWriter.Builder setRotation(@IntRange(from = 0) int rotation)

Set the image rotation in degrees.

Parameters
@IntRange(from = 0) int rotation

Rotation angle in degrees (clockwise) of the image, must be 0, 90, 180 or 270. Default is 0.

Returns
@NonNull HeifWriter.Builder

this Builder object.