ByteBufferExtractor

public class ByteBufferExtractor


Utility for extracting ByteBuffer from MPImage.

Currently it only supports MPImage with STORAGE_TYPE_BYTEBUFFER, otherwise IllegalArgumentException will be thrown.

Summary

Public methods

static ByteBuffer

Extracts a ByteBuffer from a MPImage.

static ByteBuffer
extract(MPImage image, @MPImage.MPImageFormat int targetFormat)

Extracts a readonly ByteBuffer in given targetFormat from a MPImage.

Public methods

extract

public static ByteBuffer extract(MPImage image)

Extracts a ByteBuffer from a MPImage.

The returned ByteBuffer is a read-only view, with the first available MPImageProperties whose storage type is MPImage.STORAGE_TYPE_BYTEBUFFER.

Returns
ByteBuffer

A read-only ByteBuffer.

Throws
java.lang.IllegalArgumentException

when the image doesn't contain a ByteBuffer storage.

extract

public static ByteBuffer extract(MPImage image, @MPImage.MPImageFormat int targetFormat)

Extracts a readonly ByteBuffer in given targetFormat from a MPImage.

Format conversion spec:

  • When extracting RGB images to RGBA format, A channel will always set to 255.
  • When extracting RGBA images to RGB format, A channel will be dropped.
Parameters
MPImage image

the image to extract buffer from.

@MPImage.MPImageFormat int targetFormat

the image format of the result bytebuffer.

Returns
ByteBuffer

the readonly ByteBuffer stored in MPImage

Throws
java.lang.IllegalArgumentException

when the extraction requires unsupported format or data type conversions.