public final class HeifWriter
extends Object implements AutoCloseable

   ↳ androidx.heifwriter.HeifWriter

This class writes one or more still images (of the same dimensions) into a heif file. It currently supports three input modes: INPUT_MODE_BUFFER, INPUT_MODE_SURFACE, or INPUT_MODE_BITMAP. The general sequence (in pseudo-code) to write a heif file using this class is as follows: 1) Construct the writer: HeifWriter heifwriter = new HeifWriter(...); 2) If using surface input mode, obtain the input surface: Surface surface = heifwriter.getInputSurface(); 3) Call start: heifwriter.start(); 4) Depending on the chosen input mode, add one or more images using one of these methods: heifwriter.addYuvBuffer(...); Or heifwriter.addBitmap(...); Or render to the previously obtained surface 5) Call stop: heifwriter.stop(...); 6) Close the writer: heifwriter.close(); Please refer to the documentations on individual methods for the exact usage.


Nested classes

class HeifWriter.Builder

Builder class for constructing a HeifWriter object from specified parameters. 



The input mode where the client adds bitmaps.


The input mode where the client adds input buffers with YUV data.


The input mode where the client renders the images to an input Surface created by the writer.

Public methods

void addBitmap(Bitmap bitmap)

Add one bitmap to the heif file.

void addExifData(int imageIndex, byte[] exifData, int offset, int length)

Add Exif data for the specified image.

void addYuvBuffer(int format, byte[] data)

Add one YUV buffer to the heif file.

void close()
Surface getInputSurface()

Retrieves the input surface for encoding.

void setInputEndOfStreamTimestamp(long timestampNs)

Set the timestamp (in nano seconds) of the last input frame to encode.

void start()

Start the heif writer.

void stop(long timeoutMs)

Stop the heif writer synchronously.

Inherited methods