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. |
class |
PixelCopy.Request
Represents a PixelCopy request. |
class |
PixelCopy.Result
Contains the result 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 |
static
void
|
request(Surface source, Rect srcRect, Bitmap dest, PixelCopy.OnPixelCopyFinishedListener listener, Handler listenerThread)
Requests a copy of the pixels at the provided |
static
void
|
request(SurfaceView source, Rect srcRect, Bitmap dest, PixelCopy.OnPixelCopyFinishedListener listener, Handler listenerThread)
Requests for the display content of a |
static
void
|
request(Window source, Rect srcRect, Bitmap dest, PixelCopy.OnPixelCopyFinishedListener listener, Handler listenerThread)
Requests a copy of the pixels at the provided |
static
void
|
request(Window source, Bitmap dest, PixelCopy.OnPixelCopyFinishedListener listener, Handler listenerThread)
Requests a copy of the pixels from a |
static
void
|
request(PixelCopy.Request request, Executor callbackExecutor, Consumer<PixelCopy.Result> listener)
Executes the pixel copy request |
static
void
|
request(Surface source, Bitmap dest, PixelCopy.OnPixelCopyFinishedListener listener, Handler listenerThread)
Requests a copy of the pixels from a |
Inherited methods | |
---|---|
Constants
ERROR_DESTINATION_INVALID
public static final 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
public static final 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
public static final 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
public static final int ERROR_TIMEOUT
A timeout occurred while trying to acquire a buffer from the source to copy from.
Constant Value: 2 (0x00000002)
ERROR_UNKNOWN
public static final int ERROR_UNKNOWN
The pixel copy request failed with an unknown error.
Constant Value: 1 (0x00000001)
SUCCESS
public static final int SUCCESS
The pixel copy request succeeded
Constant Value: 0 (0x00000000)
Public methods
request
public 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
.
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 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 cannot 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 cannot be null . |
listener |
PixelCopy.OnPixelCopyFinishedListener : Callback for when the pixel copy request completes
This value cannot be null . |
listenerThread |
Handler : The callback will be invoked on this Handler when
the copy is finished.
This value cannot be null . |
request
public 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
.
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 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 cannot 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 cannot be null . |
listener |
PixelCopy.OnPixelCopyFinishedListener : Callback for when the pixel copy request completes
This value cannot be null . |
listenerThread |
Handler : The callback will be invoked on this Handler when
the copy is finished.
This value cannot be null . |
request
public 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
.
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 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 cannot 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 cannot be null . |
listener |
PixelCopy.OnPixelCopyFinishedListener : Callback for when the pixel copy request completes
This value cannot be null . |
listenerThread |
Handler : The callback will be invoked on this Handler when
the copy is finished.
This value cannot be null . |
request
public 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
.
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 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 Window#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 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 OnPixelCopyFinishedListener
.
Parameters | |
---|---|
source |
Window : The source from which to copy
This value cannot 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 cannot be null . |
listener |
PixelCopy.OnPixelCopyFinishedListener : Callback for when the pixel copy request completes
This value cannot be null . |
listenerThread |
Handler : The callback will be invoked on this Handler when
the copy is finished.
This value cannot be null . |
request
public 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
.
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 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 Window#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 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 OnPixelCopyFinishedListener
.
Parameters | |
---|---|
source |
Window : The source from which to copy
This value cannot 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 cannot be null . |
listener |
PixelCopy.OnPixelCopyFinishedListener : Callback for when the pixel copy request completes
This value cannot be null . |
listenerThread |
Handler : The callback will be invoked on this Handler when
the copy is finished.
This value cannot be null . |
request
public static void request (PixelCopy.Request request, Executor callbackExecutor, Consumer<PixelCopy.Result> listener)
Executes the pixel copy request
Parameters | |
---|---|
request |
PixelCopy.Request : The request to execute
This value cannot be null . |
callbackExecutor |
Executor : The executor to run the callback on
This value cannot be null . |
listener |
Consumer : The callback for when the copy request is completed
This value cannot be null . |
request
public 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
.
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 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 cannot 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 cannot be null . |
listener |
PixelCopy.OnPixelCopyFinishedListener : Callback for when the pixel copy request completes
This value cannot be null . |
listenerThread |
Handler : The callback will be invoked on this Handler when
the copy is finished.
This value cannot be null . |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2024-04-11 UTC.