HeifWriter
class HeifWriter : AutoCloseable
kotlin.Any | |
↳ | 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.
Summary
Nested classes | |
---|---|
Builder class for constructing a HeifWriter object from specified parameters. |
Constants | |
---|---|
static Int |
The input mode where the client adds bitmaps. |
static Int |
The input mode where the client adds input buffers with YUV data. |
static Int |
The input mode where the client renders the images to an input Surface created by the writer. |
Public methods | |
---|---|
Unit |
Add one bitmap to the heif file. |
Unit |
addExifData(imageIndex: Int, @NonNull exifData: ByteArray, offset: Int, length: Int) Add Exif data for the specified image. |
Unit |
addYuvBuffer(format: Int, @NonNull data: ByteArray) Add one YUV buffer to the heif file. |
Unit |
close() |
Surface |
Retrieves the input surface for encoding. |
Unit |
setInputEndOfStreamTimestamp(timestampNs: Long) Set the timestamp (in nano seconds) of the last input frame to encode. |
Unit |
start() Start the heif writer. |
Unit |
Stop the heif writer synchronously. |
Constants
INPUT_MODE_BITMAP
static val INPUT_MODE_BITMAP: Int
The input mode where the client adds bitmaps.
Value: 2
See Also
INPUT_MODE_BUFFER
static val INPUT_MODE_BUFFER: Int
The input mode where the client adds input buffers with YUV data.
Value: 0
See Also
INPUT_MODE_SURFACE
static val INPUT_MODE_SURFACE: Int
The input mode where the client renders the images to an input Surface created by the writer. The input surface operates in single buffer mode. As a result, for use case where camera directly outputs to the input surface, this mode will not work because camera framework requires multiple buffers to operate in a pipeline fashion.
Value: 1
See Also
Public methods
addBitmap
fun addBitmap(@NonNull bitmap: Bitmap): Unit
Add one bitmap to the heif file.
Parameters | |
---|---|
bitmap |
Bitmap: the bitmap to be added to the file. |
Exceptions | |
---|---|
IllegalStateException |
if not started or not configured to use bitmap input. |
addExifData
fun addExifData(
imageIndex: Int,
@NonNull exifData: ByteArray,
offset: Int,
length: Int
): Unit
Add Exif data for the specified image. The data must be a valid Exif data block, starting with "Exif\0\0" followed by the TIFF header (See JEITA CP-3451C Section 4.5.2.)
Parameters | |
---|---|
imageIndex |
Int: index of the image, must be a valid index for the max number of image specified by Builder#setMaxImages(int) . |
exifData |
ByteArray: byte buffer containing a Exif data block. |
offset |
Int: offset of the Exif data block within exifData. |
length |
Int: length of the Exif data block. |
addYuvBuffer
fun addYuvBuffer(
format: Int,
@NonNull data: ByteArray
): Unit
Add one YUV buffer to the heif file.
Parameters | |
---|---|
format |
Int: The YUV format as defined in android.graphics.ImageFormat , currently only support YUV_420_888. |
data |
ByteArray: byte array containing the YUV data. If the format has more than one planes, they must be concatenated. |
Exceptions | |
---|---|
IllegalStateException |
if not started or not configured to use buffer input. |
close
fun close(): Unit