HeifWriter.Builder


class HeifWriter.Builder


Builder class for constructing a HeifWriter object from specified parameters.

Summary

Public constructors

Builder(
    fd: FileDescriptor,
    width: @IntRange(from = 1) Int,
    height: @IntRange(from = 1) Int,
    inputMode: Int
)

Construct a Builder with output specified by its file descriptor.

Builder(
    path: String,
    width: @IntRange(from = 1) Int,
    height: @IntRange(from = 1) Int,
    inputMode: Int
)

Construct a Builder with output specified by its path.

Public functions

HeifWriter

Build a HeifWriter object.

HeifWriter.Builder
setGridEnabled(gridEnabled: Boolean)

Set whether to enable grid option.

HeifWriter.Builder
setHandler(handler: Handler?)

Provide a handler for the HeifWriter to use.

HeifWriter.Builder
setMaxImages(maxImages: @IntRange(from = 1) Int)

Set the maximum number of images to write.

HeifWriter.Builder
setPrimaryIndex(primaryIndex: @IntRange(from = 0) Int)

Set the primary image index.

HeifWriter.Builder
setQuality(quality: @IntRange(from = 0, to = 100) Int)

Set the quality for encoding images.

HeifWriter.Builder
setRotation(rotation: @IntRange(from = 0) Int)

Set the image rotation in degrees.

Public constructors

Builder

Added in 1.0.0
Builder(
    fd: FileDescriptor,
    width: @IntRange(from = 1) Int,
    height: @IntRange(from = 1) Int,
    inputMode: Int
)

Construct a Builder with output specified by its file descriptor.

Parameters
fd: FileDescriptor

File descriptor of the file to be written.

width: @IntRange(from = 1) Int

Width of the image in number of pixels.

height: @IntRange(from = 1) Int

Height of the image in number of pixels.

inputMode: Int

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
Builder(
    path: String,
    width: @IntRange(from = 1) Int,
    height: @IntRange(from = 1) Int,
    inputMode: Int
)

Construct a Builder with output specified by its path.

Parameters
path: String

Path of the file to be written.

width: @IntRange(from = 1) Int

Width of the image in number of pixels.

height: @IntRange(from = 1) Int

Height of the image in number of pixels.

inputMode: Int

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

Public functions

build

Added in 1.0.0
fun build(): HeifWriter

Build a HeifWriter object.

Returns
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
fun setGridEnabled(gridEnabled: Boolean): HeifWriter.Builder

Set whether to enable grid option.

Parameters
gridEnabled: Boolean

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

Returns
HeifWriter.Builder

this Builder object.

setHandler

Added in 1.0.0
fun setHandler(handler: Handler?): HeifWriter.Builder

Provide a handler for the HeifWriter to use.

Parameters
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
HeifWriter.Builder

this Builder object.

setMaxImages

Added in 1.0.0
fun setMaxImages(maxImages: @IntRange(from = 1) Int): HeifWriter.Builder

Set the maximum number of images to write.

Parameters
maxImages: @IntRange(from = 1) Int

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
HeifWriter.Builder

this Builder object.

setPrimaryIndex

Added in 1.0.0
fun setPrimaryIndex(primaryIndex: @IntRange(from = 0) Int): HeifWriter.Builder

Set the primary image index.

Parameters
primaryIndex: @IntRange(from = 0) Int

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

Returns
HeifWriter.Builder

this Builder object.

setQuality

Added in 1.0.0
fun setQuality(quality: @IntRange(from = 0, to = 100) Int): HeifWriter.Builder

Set the quality for encoding images.

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

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

Returns
HeifWriter.Builder

this Builder object.

setRotation

Added in 1.0.0
fun setRotation(rotation: @IntRange(from = 0) Int): HeifWriter.Builder

Set the image rotation in degrees.

Parameters
rotation: @IntRange(from = 0) Int

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

Returns
HeifWriter.Builder

this Builder object.