PixelCopy
class PixelCopy
kotlin.Any | |
↳ | android.view.PixelCopy |
Provides a mechanisms to issue pixel copy requests to allow for copy operations from Surface
to Bitmap
Summary
Nested classes | |
---|---|
abstract |
Listener for observing the completion of a PixelCopy request. |
Represents a PixelCopy request. |
|
Contains the result of a PixelCopy request |
Constants | |
---|---|
static Int |
The destination isn't a valid copy target. |
static Int |
It is not possible to copy from the source. |
static Int |
The source has nothing to copy from. |
static Int |
A timeout occurred while trying to acquire a buffer from the source to copy from. |
static Int |
The pixel copy request failed with an unknown error. |
static Int |
The pixel copy request succeeded |
Public methods | |
---|---|
static Unit |
request(request: PixelCopy.Request, callbackExecutor: Executor, listener: Consumer<PixelCopy.Result!>) Executes the pixel copy request |
static Unit |
request(source: Surface, dest: Bitmap, listener: PixelCopy.OnPixelCopyFinishedListener, listenerThread: Handler) Requests a copy of the pixels from a |
static Unit |
request(source: Surface, srcRect: Rect?, dest: Bitmap, listener: PixelCopy.OnPixelCopyFinishedListener, listenerThread: Handler) Requests a copy of the pixels at the provided |
static Unit |
request(source: SurfaceView, dest: Bitmap, listener: PixelCopy.OnPixelCopyFinishedListener, listenerThread: Handler) Requests for the display content of a |
static Unit |
request(source: SurfaceView, srcRect: Rect?, dest: Bitmap, listener: PixelCopy.OnPixelCopyFinishedListener, listenerThread: Handler) Requests for the display content of a |
static Unit |
request(source: Window, dest: Bitmap, listener: PixelCopy.OnPixelCopyFinishedListener, listenerThread: Handler) Requests a copy of the pixels from a |
static Unit |
request(source: Window, srcRect: Rect?, dest: Bitmap, listener: PixelCopy.OnPixelCopyFinishedListener, listenerThread: Handler) Requests a copy of the pixels at the provided |
Constants
ERROR_DESTINATION_INVALID
static val ERROR_DESTINATION_INVALID: Int
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.
Value: 5
ERROR_SOURCE_INVALID
static val ERROR_SOURCE_INVALID: Int
It is not possible to copy from the source. This can happen if the source is hardware-protected or destroyed.
Value: 4
ERROR_SOURCE_NO_DATA
static val ERROR_SOURCE_NO_DATA: Int
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.
Value: 3
ERROR_TIMEOUT
static val ERROR_TIMEOUT: Int
A timeout occurred while trying to acquire a buffer from the source to copy from.
Value: 2
ERROR_UNKNOWN
static val ERROR_UNKNOWN: Int
The pixel copy request failed with an unknown error.
Value: 1
Public methods
request
static fun request(
request: PixelCopy.Request,
callbackExecutor: Executor,
listener: Consumer<PixelCopy.Result!>
): Unit
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<PixelCopy.Result!>: The callback for when the copy request is completed This value cannot be null . |
request
static fun request(
source: Surface,
dest: Bitmap,
listener: PixelCopy.OnPixelCopyFinishedListener,
listenerThread: Handler
): Unit
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 . |
request
static fun request(
source: Surface,
srcRect: Rect?,
dest: Bitmap,
listener: PixelCopy.OnPixelCopyFinishedListener,
listenerThread: Handler
): Unit
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
static fun request(
source: SurfaceView,
dest: Bitmap,
listener: PixelCopy.OnPixelCopyFinishedListener,
listenerThread: Handler
): Unit
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
static fun request(
source: SurfaceView,
srcRect: Rect?,
dest: Bitmap,
listener: PixelCopy.OnPixelCopyFinishedListener,
listenerThread: Handler
): Unit
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
static fun request(
source: Window,
dest: Bitmap,
listener: PixelCopy.OnPixelCopyFinishedListener,
listenerThread: Handler
): Unit
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
static fun request(
source: Window,
srcRect: Rect?,
dest: Bitmap,
listener: PixelCopy.OnPixelCopyFinishedListener,
listenerThread: Handler
): Unit
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 . |