FileDocCategorySizeDatePackage
Image.javaAPI DocAndroid 5.1 API8247Thu Mar 12 22:22:30 GMT 2015android.media

Image

public abstract class Image extends Object implements AutoCloseable

A single complete image buffer to use with a media source such as a {@link MediaCodec} or a {@link android.hardware.camera2.CameraDevice CameraDevice}.

This class allows for efficient direct application access to the pixel data of the Image through one or more {@link java.nio.ByteBuffer ByteBuffers}. Each buffer is encapsulated in a {@link Plane} that describes the layout of the pixel data in that plane. Due to this direct access, and unlike the {@link android.graphics.Bitmap Bitmap} class, Images are not directly usable as as UI resources.

Since Images are often directly produced or consumed by hardware components, they are a limited resource shared across the system, and should be closed as soon as they are no longer needed.

For example, when using the {@link ImageReader} class to read out Images from various media sources, not closing old Image objects will prevent the availability of new Images once {@link ImageReader#getMaxImages the maximum outstanding image count} is reached. When this happens, the function acquiring new Images will typically throw an {@link IllegalStateException}.

see
ImageReader

Fields Summary
private android.graphics.Rect
mCropRect
Constructors Summary
protected Image()

hide

    
Methods Summary
public abstract voidclose()
Free up this frame for reuse.

After calling this method, calling any methods on this {@code Image} will result in an {@link IllegalStateException}, and attempting to read from {@link ByteBuffer ByteBuffers} returned by an earlier {@link Plane#getBuffer} call will have undefined behavior.

public android.graphics.RectgetCropRect()
Get the crop rectangle associated with this frame.

The crop rectangle specifies the region of valid pixels in the image, using coordinates in the largest-resolution plane.

        if (mCropRect == null) {
            return new Rect(0, 0, getWidth(), getHeight());
        } else {
            return new Rect(mCropRect); // return a copy
        }
    
public abstract intgetFormat()
Get the format for this image. This format determines the number of ByteBuffers needed to represent the image, and the general layout of the pixel data in each in ByteBuffer.

The format is one of the values from {@link android.graphics.ImageFormat ImageFormat}. The mapping between the formats and the planes is as follows:

Format Plane count Layout details
{@link android.graphics.ImageFormat#JPEG JPEG} 1 Compressed data, so row and pixel strides are 0. To uncompress, use {@link android.graphics.BitmapFactory#decodeByteArray BitmapFactory#decodeByteArray}.
{@link android.graphics.ImageFormat#YUV_420_888 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.
{@link android.graphics.ImageFormat#RAW_SENSOR 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 {@link android.hardware.camera2.CameraDevice CameraDevice}.

see
android.graphics.ImageFormat

public abstract intgetHeight()
The height of the image in pixels. For formats where some color channels are subsampled, this is the height of the largest-resolution plane.

public abstract android.media.Image$Plane[]getPlanes()
Get the array of pixel planes for this Image. The number of planes is determined by the format of the Image.

public abstract longgetTimestamp()
Get the timestamp associated with this frame.

The timestamp is measured in nanoseconds, and is monotonically increasing. However, the zero point and whether the timestamp can be compared against other sources of time or images depend on the source of this image.

public abstract intgetWidth()
The width of the image in pixels. For formats where some color channels are subsampled, this is the width of the largest-resolution plane.

public voidsetCropRect(android.graphics.Rect cropRect)
Set the crop rectangle associated with this frame.

The crop rectangle specifies the region of valid pixels in the image, using coordinates in the largest-resolution plane.

        if (cropRect != null) {
            cropRect = new Rect(cropRect);  // make a copy
            cropRect.intersect(0, 0, getWidth(), getHeight());
        }
        mCropRect = cropRect;