Most visited

Recently visited

Added in API level 24

PixelCopy

public final class PixelCopy
extends Object

java.lang.Object
   ↳ android.view.PixelCopy


Provides a mechanisms to issue pixel copy requests to allow for copy operations from Surface to Bitmap

Summary

Nested classes

interface PixelCopy.OnPixelCopyFinishedListener

Listener for observing the completion of a PixelCopy request. 

Constants

int ERROR_DESTINATION_INVALID

The destination isn't a valid copy target.

int ERROR_SOURCE_INVALID

It is not possible to copy from the source.

int ERROR_SOURCE_NO_DATA

The source has nothing to copy from.

int ERROR_TIMEOUT

A timeout occurred while trying to acquire a buffer from the source to copy from.

int ERROR_UNKNOWN

The pixel copy request failed with an unknown error.

int SUCCESS

The pixel copy request succeeded

Public methods

static void request(SurfaceView source, Bitmap dest, PixelCopy.OnPixelCopyFinishedListener listener, Handler listenerThread)

Requests for the display content of a SurfaceView to be copied into a provided Bitmap.

static void request(Surface source, Bitmap dest, PixelCopy.OnPixelCopyFinishedListener listener, Handler listenerThread)

Requests a copy of the pixels from a Surface to be copied into a provided Bitmap.

Inherited methods

From class java.lang.Object

Constants

ERROR_DESTINATION_INVALID

Added in API level 24
int ERROR_DESTINATION_INVALID

The destination isn't a valid copy target. If the destination is a bitmap this can occur if the bitmap is too large for the hardware to copy to. It can also occur if the destination has been destroyed.

Constant Value: 5 (0x00000005)

ERROR_SOURCE_INVALID

Added in API level 24
int ERROR_SOURCE_INVALID

It is not possible to copy from the source. This can happen if the source is hardware-protected or destroyed.

Constant Value: 4 (0x00000004)

ERROR_SOURCE_NO_DATA

Added in API level 24
int ERROR_SOURCE_NO_DATA

The source has nothing to copy from. When the source is a Surface this means that no buffers have been queued yet. Wait for the source to produce a frame and try again.

Constant Value: 3 (0x00000003)

ERROR_TIMEOUT

Added in API level 24
int ERROR_TIMEOUT

A timeout occurred while trying to acquire a buffer from the source to copy from.

Constant Value: 2 (0x00000002)

ERROR_UNKNOWN

Added in API level 24
int ERROR_UNKNOWN

The pixel copy request failed with an unknown error.

Constant Value: 1 (0x00000001)

SUCCESS

Added in API level 24
int SUCCESS

The pixel copy request succeeded

Constant Value: 0 (0x00000000)

Public methods

request

Added in API level 24
void request (SurfaceView source, 
                Bitmap dest, 
                PixelCopy.OnPixelCopyFinishedListener listener, 
                Handler listenerThread)

Requests for the display content of a SurfaceView to be copied into a provided Bitmap. The contents of the source will be scaled to fit exactly inside the bitmap. The pixel format of the source buffer will be converted, as part of the copy, to fit the the bitmap's Bitmap.Config. The most recently queued buffer in the SurfaceView's Surface will be used as the source of the copy.

Parameters
source SurfaceView: The source from which to copy
dest Bitmap: The destination of the copy. The source will be scaled to match the width, height, and format of this bitmap.
listener PixelCopy.OnPixelCopyFinishedListener: Callback for when the pixel copy request completes
listenerThread Handler: The callback will be invoked on this Handler when the copy is finished.

request

Added in API level 24
void request (Surface source, 
                Bitmap dest, 
                PixelCopy.OnPixelCopyFinishedListener listener, 
                Handler listenerThread)

Requests a copy of the pixels from a Surface to be copied into a provided Bitmap. The contents of the source will be scaled to fit exactly inside the bitmap. The pixel format of the source buffer will be converted, as part of the copy, to fit the the bitmap's Bitmap.Config. The most recently queued buffer in the Surface will be used as the source of the copy.

Parameters
source Surface: The source from which to copy
dest Bitmap: The destination of the copy. The source will be scaled to match the width, height, and format of this bitmap.
listener PixelCopy.OnPixelCopyFinishedListener: Callback for when the pixel copy request completes
listenerThread Handler: The callback will be invoked on this Handler when the copy is finished.

Hooray!