Encoding LIF Images

Encode Multiview Images to Leia Image Format using the Media SDK.

You learnt about decoding images using the Multiview Image Decoder in the previous sections. Many a times, you might also want to encode the image back to a Leia Image Format, based on your app's use case.

The advantage of using Leia Image Format is its ability to appear as a regular image on a normal device. The Android Media SDK provides an easy-to-use MultiviewImageEncoder to encode a Multiview Image to a LIF.

Using the Multiview Image Encoder

You can obtain an instance of the MultiviewImageEncoder using the getDefault() function.

val encoder = MultiviewImageEncoder.getDefault()

Encoding the image

You can call encode() on the MultiviewImageEncoder to encode an image by passing the Multiview image as a parameter.

val encoder = MultiviewImageEncoder.getDefault()
val encodedBytes = encoder.encode(multiviewImage)

This will handle all the encoding for the ViewPoints, disparity and the global metadata of the MultiviewImage. After encoding, it will return the MultiviewImage as raw bytes. You can use these bytes to easily write to a FileOutputStream.

Optionally, you can also use the overloaded function to tweak the JPEG image quality percentage while encoding. By default, the encoder encodes at 100% quality, if not specified.

val encoder = MultiviewImageEncoder.getDefault()
val encodedBytes = encoder.encode(multiviewImage, 70) // 70% quality

The encode() function must be called on a worker thread.

Last updated

Copyright © 2023 Leia Inc. All Rights Reserved