WindowCapture


public final class WindowCapture


Summary

Public methods

static final @NonNull Bitmap
captureRegionToBitmap(@NonNull Window receiver, Rect boundsInWindow)

Suspend function that captures an image of the underlying window into a Bitmap.

static final @NonNull ListenableFuture<@NonNull Bitmap>
captureRegionToBitmapAsync(@NonNull Window receiver, Rect boundsInWindow)

A ListenableFuture variant of captureRegionToBitmap intended for use from Java.

Public methods

captureRegionToBitmap

public static final @NonNull Bitmap captureRegionToBitmap(@NonNull Window receiver, Rect boundsInWindow)

Suspend function that captures an image of the underlying window into a Bitmap.

For devices below Build.VERSION_CODES#O the image is obtained using View#draw on the windows decorView. Otherwise, PixelCopy is used.

This method will also enable HardwareRendererCompat#setDrawingEnabled(boolean) if required.

This API is primarily intended for use in lower layer libraries or frameworks. For test authors, its recommended to use espresso or compose's captureToImage.

This API must be called from the UI thread.

The resulting image is captured after forcing the View to redraw, and waiting for the draw to operation complete. This is done as a means to improve the stability of the resulting image - especially in cases where hardware rendering drawing is off initially.

captureRegionToBitmapAsync

public static final @NonNull ListenableFuture<@NonNull BitmapcaptureRegionToBitmapAsync(@NonNull Window receiver, Rect boundsInWindow)

A ListenableFuture variant of captureRegionToBitmap intended for use from Java.