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.
Kotlin
Java
1
val encoder = MultiviewImageEncoder.getDefault()
Copied!
1
MultiviewImageEncoder encoder = MultiviewImageEncoder.getDefault();
Copied!

Encoding the image

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