public static class MediaCodec.MediaImage extends Image
Image.Plane
mIsImageValid
Constructor and Description |
---|
MediaImage(ByteBuffer buffer,
ByteBuffer info,
boolean readOnly,
long timestamp,
int xOffset,
int yOffset,
Rect cropRect) |
Modifier and Type | Method and Description |
---|---|
void |
close()
Free up this frame for reuse.
|
int |
getFormat()
Get the format for this image.
|
int |
getHeight()
The height of the image in pixels.
|
Image.Plane[] |
getPlanes()
Get the array of pixel planes for this Image.
|
long |
getTimestamp()
Get the timestamp associated with this frame.
|
int |
getWidth()
The width of the image in pixels.
|
void |
setCropRect(Rect cropRect)
Set the crop rectangle associated with this frame.
|
getCropRect, setTimestamp, throwISEIfImageIsInvalid
public MediaImage(ByteBuffer buffer, ByteBuffer info, boolean readOnly, long timestamp, int xOffset, int yOffset, Rect cropRect)
public int getFormat()
Image
The format is one of the values from
ImageFormat
. The mapping between the
formats and the planes is as follows:
Format | Plane count | Layout details |
---|---|---|
JPEG |
1 | Compressed data, so row and pixel strides are 0. To uncompress, use
BitmapFactory#decodeByteArray .
|
YUV_420_888 |
3 | A luminance plane followed by the Cb and Cr chroma planes. The chroma planes have half the width and height of the luminance plane (4:2:0 subsampling). Each pixel sample in each plane has 8 bits. Each plane has its own row stride and pixel stride. |
YUV_422_888 |
3 | A luminance plane followed by the Cb and Cr chroma planes. The chroma planes have half the width and the full height of the luminance plane (4:2:2 subsampling). Each pixel sample in each plane has 8 bits. Each plane has its own row stride and pixel stride. |
YUV_444_888 |
3 | A luminance plane followed by the Cb and Cr chroma planes. The chroma planes have the same width and height as that of the luminance plane (4:4:4 subsampling). Each pixel sample in each plane has 8 bits. Each plane has its own row stride and pixel stride. |
FLEX_RGB_888 |
3 | A R (red) plane followed by the G (green) and B (blue) planes. All planes have the same widths and heights. Each pixel sample in each plane has 8 bits. Each plane has its own row stride and pixel stride. |
FLEX_RGBA_8888 |
4 | A R (red) plane followed by the G (green), B (blue), and A (alpha) planes. All planes have the same widths and heights. Each pixel sample in each plane has 8 bits. Each plane has its own row stride and pixel stride. |
RAW_SENSOR |
1 | A single plane of raw sensor image data, with 16 bits per color
sample. The details of the layout need to be queried from the source of
the raw sensor data, such as
CameraDevice .
|
RAW_PRIVATE |
1 | A single plane of raw sensor image data of private layout.
The details of the layout is implementation specific. Row stride and
pixel stride are undefined for this format. Calling Image.Plane.getRowStride()
or Image.Plane.getPixelStride() on RAW_PRIVATE image will cause
UnSupportedOperationException being thrown.
|
getFormat
in class Image
ImageFormat
public int getHeight()
Image
public int getWidth()
Image
public long getTimestamp()
Image
The timestamp is measured in nanoseconds, and is normally monotonically
increasing. The timestamps for the images from different sources may have
different timebases therefore may not be comparable. The specific meaning and
timebase of the timestamp depend on the source providing images. See
Camera
,
CameraDevice
,
MediaPlayer
and MediaCodec
for more details.
getTimestamp
in class Image
public Image.Plane[] getPlanes()
Image
PRIVATE
, because the image pixel data is not directly accessible. The
application can check the image format by calling
Image.getFormat()
.public void close()
Image
After calling this method, calling any methods on this Image
will
result in an IllegalStateException
, and attempting to read from
or write to ByteBuffers
returned by an earlier
Image.Plane.getBuffer()
call will have undefined behavior. If the image
was obtained from ImageWriter
via
ImageWriter.dequeueInputImage()
, after calling this method, any
image data filled by the application will be lost and the image will be
returned to ImageWriter
for reuse. Images given to
queueInputImage()
are automatically
closed.
close
in interface AutoCloseable
close
in class Image
public void setCropRect(Rect cropRect)
The crop rectangle specifies the region of valid pixels in the image, using coordinates in the largest-resolution plane.
setCropRect
in class Image