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.You can obtain an instance of the
MultiviewImageEncoder
using the getDefault()
function.Kotlin
Java
val encoder = MultiviewImageEncoder.getDefault()
MultiviewImageEncoder encoder = MultiviewImageEncoder.getDefault();
You can call
encode()
on the MultiviewImageEncoder
to encode an image by passing the Multiview image as a parameter.Kotlin
Java
val encoder = MultiviewImageEncoder.getDefault()
val encodedBytes = encoder.encode(multiviewImage)
MultiviewImageEncoder encoder = MultiviewImageEncoder.getDefault();
byte[] 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.
Kotlin
Java
val encoder = MultiviewImageEncoder.getDefault()
val encodedBytes = encoder.encode(multiviewImage, 70) // 70% quality
MultiviewImageEncoder encoder = MultiviewImageEncoder.getDefault();
byte[] encodedBytes = encoder.encode(multiviewImage);
The
encode()
function must be called on a worker thread.Last modified 2yr ago