Skip to content

Most visited

Recently visited

navigation

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, Rect srcRect, Bitmap dest, PixelCopy.OnPixelCopyFinishedListener listener, Handler listenerThread)

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

static void request(SurfaceView source, Rect srcRect, 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(Window source, Rect srcRect, Bitmap dest, PixelCopy.OnPixelCopyFinishedListener listener, Handler listenerThread)

Requests a copy of the pixels at the provided Rect from a Window to be copied into a provided Bitmap.

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

Requests a copy of the pixels from a Window 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

This value must never be null.

dest Bitmap: The destination of the copy. The source will be scaled to match the width, height, and format of this bitmap.

This value must never be null.

listener PixelCopy.OnPixelCopyFinishedListener: Callback for when the pixel copy request completes

This value must never be null.

listenerThread Handler: The callback will be invoked on this Handler when the copy is finished.

This value must never be null.

request

added in API level 26
void request (Surface source, 
                Rect srcRect, 
                Bitmap dest, 
                PixelCopy.OnPixelCopyFinishedListener listener, 
                Handler listenerThread)

Requests a copy of the pixels at the provided Rect from a Surface to be copied into a provided Bitmap. The contents of the source rect 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

This value must never be null.

srcRect Rect: The area of the source to copy from. If this is null the copy area will be the entire surface. The rect will be clamped to the bounds of the Surface.

dest Bitmap: The destination of the copy. The source will be scaled to match the width, height, and format of this bitmap.

This value must never be null.

listener PixelCopy.OnPixelCopyFinishedListener: Callback for when the pixel copy request completes

This value must never be null.

listenerThread Handler: The callback will be invoked on this Handler when the copy is finished.

This value must never be null.

request

added in API level 26
void request (SurfaceView source, 
                Rect srcRect, 
                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

This value must never be null.

srcRect Rect: The area of the source to copy from. If this is null the copy area will be the entire surface. The rect will be clamped to the bounds of the Surface.

dest Bitmap: The destination of the copy. The source will be scaled to match the width, height, and format of this bitmap.

This value must never be null.

listener PixelCopy.OnPixelCopyFinishedListener: Callback for when the pixel copy request completes

This value must never be null.

listenerThread Handler: The callback will be invoked on this Handler when the copy is finished.

This value must never be null.

request

added in API level 26
void request (Window source, 
                Rect srcRect, 
                Bitmap dest, 
                PixelCopy.OnPixelCopyFinishedListener listener, 
                Handler listenerThread)

Requests a copy of the pixels at the provided Rect from a Window to be copied into a provided Bitmap. The contents of the source rect 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 Window's Surface will be used as the source of the copy. Note: This is limited to being able to copy from Window's with a non-null DecorView. If peekDecorView() is null this throws an IllegalArgumentException. It will similarly throw an exception if the DecorView has not yet acquired a backing surface. It is recommended that ViewTreeObserver.OnDrawListener is used to ensure that at least one draw has happened before trying to copy from the window, otherwise either an IllegalArgumentException will be thrown or an error will be returned to the PixelCopy.OnPixelCopyFinishedListener.

Parameters
source Window: The source from which to copy

This value must never be null.

srcRect Rect: The area of the source to copy from. If this is null the copy area will be the entire surface. The rect will be clamped to the bounds of the Surface.

dest Bitmap: The destination of the copy. The source will be scaled to match the width, height, and format of this bitmap.

This value must never be null.

listener PixelCopy.OnPixelCopyFinishedListener: Callback for when the pixel copy request completes

This value must never be null.

listenerThread Handler: The callback will be invoked on this Handler when the copy is finished.

This value must never be null.

request

added in API level 26
void request (Window source, 
                Bitmap dest, 
                PixelCopy.OnPixelCopyFinishedListener listener, 
                Handler listenerThread)

Requests a copy of the pixels from a Window 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 Window's Surface will be used as the source of the copy. Note: This is limited to being able to copy from Window's with a non-null DecorView. If peekDecorView() is null this throws an IllegalArgumentException. It will similarly throw an exception if the DecorView has not yet acquired a backing surface. It is recommended that ViewTreeObserver.OnDrawListener is used to ensure that at least one draw has happened before trying to copy from the window, otherwise either an IllegalArgumentException will be thrown or an error will be returned to the PixelCopy.OnPixelCopyFinishedListener.

Parameters
source Window: The source from which to copy

This value must never be null.

dest Bitmap: The destination of the copy. The source will be scaled to match the width, height, and format of this bitmap.

This value must never be null.

listener PixelCopy.OnPixelCopyFinishedListener: Callback for when the pixel copy request completes

This value must never be null.

listenerThread Handler: The callback will be invoked on this Handler when the copy is finished.

This value must never be null.

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

This value must never be null.

dest Bitmap: The destination of the copy. The source will be scaled to match the width, height, and format of this bitmap.

This value must never be null.

listener PixelCopy.OnPixelCopyFinishedListener: Callback for when the pixel copy request completes

This value must never be null.

listenerThread Handler: The callback will be invoked on this Handler when the copy is finished.

This value must never be null.

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a one-minute survey?
Help us improve Android tools and documentation.