# PixelCopy.Request.Builder

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

# Builder

*** ** * ** ***

Kotlin \|[Java](https://developer.android.com/reference/android/view/PixelCopy.Request.Builder "View this page in Java")  

```
class Builder
```

|---|----------------------------------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)                                                   ||
| ↳ | [android.view.PixelCopy.Request.Builder](https://developer.android.com/reference/kotlin/android/view/PixelCopy.Request.Builder#) |

A builder to create the complete PixelCopy request, which is then executed by calling [request(android.view.PixelCopy.Request,java.util.concurrent.Executor,java.util.function.Consumer)](https://developer.android.com/reference/kotlin/android/view/PixelCopy#request(android.view.PixelCopy.Request,%20java.util.concurrent.Executor,%20java.util.function.Consumer)) with the built request returned from [build()](https://developer.android.com/reference/kotlin/android/view/PixelCopy.Request.Builder#build())

## Summary

|                                                                                                                                                                                                                                                                                              Public methods                                                                                                                                                                                                                                                                                               ||
|----------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [PixelCopy.Request](https://developer.android.com/reference/kotlin/android/view/PixelCopy.Request)                         | [build](https://developer.android.com/reference/kotlin/android/view/PixelCopy.Request.Builder#build())`()` <br />                                                                                                                                                                                                                                                                                                                                                             |
| static [PixelCopy.Request.Builder](https://developer.android.com/reference/kotlin/android/view/PixelCopy.Request.Builder#) | [ofSurface](https://developer.android.com/reference/kotlin/android/view/PixelCopy.Request.Builder#ofSurface(android.view.Surface))`(`source:` `[Surface](https://developer.android.com/reference/kotlin/android/view/Surface)`)` Creates a PixelCopy Builder for the given [Surface](https://developer.android.com/reference/kotlin/android/view/Surface)                                                                                                                     |
| static [PixelCopy.Request.Builder](https://developer.android.com/reference/kotlin/android/view/PixelCopy.Request.Builder#) | [ofSurface](https://developer.android.com/reference/kotlin/android/view/PixelCopy.Request.Builder#ofSurface(android.view.SurfaceView))`(`source:` `[SurfaceView](https://developer.android.com/reference/kotlin/android/view/SurfaceView)`)` Creates a PixelCopy Builder for the [Surface](https://developer.android.com/reference/kotlin/android/view/Surface) belonging to the given [SurfaceView](https://developer.android.com/reference/kotlin/android/view/SurfaceView) |
| static [PixelCopy.Request.Builder](https://developer.android.com/reference/kotlin/android/view/PixelCopy.Request.Builder#) | [ofWindow](https://developer.android.com/reference/kotlin/android/view/PixelCopy.Request.Builder#ofWindow(android.view.View))`(`source:` `[View](https://developer.android.com/reference/kotlin/android/view/View)`)` Creates a PixelCopy Builder for the [Window](https://developer.android.com/reference/kotlin/android/view/Window) that the given [View](https://developer.android.com/reference/kotlin/android/view/View) is attached to.                                |
| static [PixelCopy.Request.Builder](https://developer.android.com/reference/kotlin/android/view/PixelCopy.Request.Builder#) | [ofWindow](https://developer.android.com/reference/kotlin/android/view/PixelCopy.Request.Builder#ofWindow(android.view.Window))`(`source:` `[Window](https://developer.android.com/reference/kotlin/android/view/Window)`)` Creates a PixelCopy Builder for the given [Window](https://developer.android.com/reference/kotlin/android/view/Window)                                                                                                                            |
| [PixelCopy.Request.Builder](https://developer.android.com/reference/kotlin/android/view/PixelCopy.Request.Builder#)        | [setDestinationBitmap](https://developer.android.com/reference/kotlin/android/view/PixelCopy.Request.Builder#setDestinationBitmap(android.graphics.Bitmap))`(`destination:` `[Bitmap](https://developer.android.com/reference/kotlin/android/graphics/Bitmap.html#)?`)` Specifies the output bitmap in which to store the result.                                                                                                                                             |
| [PixelCopy.Request.Builder](https://developer.android.com/reference/kotlin/android/view/PixelCopy.Request.Builder#)        | [setSourceRect](https://developer.android.com/reference/kotlin/android/view/PixelCopy.Request.Builder#setSourceRect(android.graphics.Rect))`(`srcRect:` `[Rect](https://developer.android.com/reference/kotlin/android/graphics/Rect.html#)?`)` Sets the region of the source to copy from.                                                                                                                                                                                   |

## Public methods

### build

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun build(): PixelCopy.Request
```

|                                                                                                                    Return                                                                                                                     ||
|----------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------|
| [PixelCopy.Request](https://developer.android.com/reference/kotlin/android/view/PixelCopy.Request) | The built [PixelCopy.Request](https://developer.android.com/reference/kotlin/android/view/PixelCopy.Request) This value cannot be `null`. |

### ofSurface

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
static fun ofSurface(source: Surface): PixelCopy.Request.Builder
```

Creates a PixelCopy Builder for the given [Surface](https://developer.android.com/reference/kotlin/android/view/Surface)

|                                                                                                                    Parameters                                                                                                                    ||
|----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `source` | [Surface](https://developer.android.com/reference/kotlin/android/view/Surface): The Surface to copy from. Must be [valid](https://developer.android.com/reference/kotlin/android/view/Surface#isValid()). This value cannot be `null`. |

|                                                                                                                                                    Return                                                                                                                                                     ||
|---------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [PixelCopy.Request.Builder](https://developer.android.com/reference/kotlin/android/view/PixelCopy.Request.Builder#) | A [Builder](https://developer.android.com/reference/kotlin/android/view/PixelCopy.Request.Builder#) builder to set the optional params \& build the request This value cannot be `null`. |

### ofSurface

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
static fun ofSurface(source: SurfaceView): PixelCopy.Request.Builder
```

Creates a PixelCopy Builder for the [Surface](https://developer.android.com/reference/kotlin/android/view/Surface) belonging to the given [SurfaceView](https://developer.android.com/reference/kotlin/android/view/SurfaceView)

|                                                                                                                                   Parameters                                                                                                                                    ||
|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `source` | [SurfaceView](https://developer.android.com/reference/kotlin/android/view/SurfaceView): The SurfaceView to copy from. The backing surface must be [valid](https://developer.android.com/reference/kotlin/android/view/Surface#isValid()) This value cannot be `null`. |

|                                                                                                                                                    Return                                                                                                                                                     ||
|---------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [PixelCopy.Request.Builder](https://developer.android.com/reference/kotlin/android/view/PixelCopy.Request.Builder#) | A [Builder](https://developer.android.com/reference/kotlin/android/view/PixelCopy.Request.Builder#) builder to set the optional params \& build the request This value cannot be `null`. |

### ofWindow

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
static fun ofWindow(source: View): PixelCopy.Request.Builder
```

Creates a PixelCopy Builder for the [Window](https://developer.android.com/reference/kotlin/android/view/Window) that the given [View](https://developer.android.com/reference/kotlin/android/view/View) is attached to. Note that this copy request is not cropped to the area the View occupies by default. If that behavior is desired, use [View.getLocationInWindow(int[])](https://developer.android.com/reference/kotlin/android/view/View#getLocationInWindow(kotlin.IntArray)) combined with [Builder.setSourceRect(Rect)](https://developer.android.com/reference/kotlin/android/view/PixelCopy.Request.Builder#setSourceRect(android.graphics.Rect)) to set a crop area to restrict the copy operation.

|                                                                                                                                              Parameters                                                                                                                                              ||
|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `source` | [View](https://developer.android.com/reference/kotlin/android/view/View): A View that [is attached](https://developer.android.com/reference/kotlin/android/view/View#isAttachedToWindow()) to a window that will be used to retrieve the window to copy from. This value cannot be `null`. |

|                                                                                                                                                    Return                                                                                                                                                     ||
|---------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [PixelCopy.Request.Builder](https://developer.android.com/reference/kotlin/android/view/PixelCopy.Request.Builder#) | A [Builder](https://developer.android.com/reference/kotlin/android/view/PixelCopy.Request.Builder#) builder to set the optional params \& build the request This value cannot be `null`. |

### ofWindow

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
static fun ofWindow(source: Window): PixelCopy.Request.Builder
```

Creates a PixelCopy Builder for the given [Window](https://developer.android.com/reference/kotlin/android/view/Window)

|                                                                  Parameters                                                                  ||
|----------|------------------------------------------------------------------------------------------------------------------------------------|
| `source` | [Window](https://developer.android.com/reference/kotlin/android/view/Window): The Window to copy from This value cannot be `null`. |

|                                                                                                                                                    Return                                                                                                                                                     ||
|---------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [PixelCopy.Request.Builder](https://developer.android.com/reference/kotlin/android/view/PixelCopy.Request.Builder#) | A [Builder](https://developer.android.com/reference/kotlin/android/view/PixelCopy.Request.Builder#) builder to set the optional params \& build the request This value cannot be `null`. |

### setDestinationBitmap

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun setDestinationBitmap(destination: Bitmap?): PixelCopy.Request.Builder
```

Specifies the output bitmap in which to store the result. By default, a Bitmap of format [android.graphics.Bitmap.Config#ARGB_8888](https://developer.android.com/reference/kotlin/android/graphics/Bitmap.Config.html#) with a width \& height matching that of the [source area](https://developer.android.com/reference/kotlin/android/view/PixelCopy.Request.Builder#setSourceRect(android.graphics.Rect)) will be created to place the result.

|                                                                                                                                                                                                                          Parameters                                                                                                                                                                                                                           ||
|---------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `destination` | [Bitmap](https://developer.android.com/reference/kotlin/android/graphics/Bitmap.html#)?: The bitmap to store the result, or null to have a bitmap automatically created of the appropriate size. If not null, must not be [recycled](https://developer.android.com/reference/kotlin/android/graphics/Bitmap.html#isRecycled()) and must be [mutable](https://developer.android.com/reference/kotlin/android/graphics/Bitmap.html#isMutable()). |

|                                                                         Return                                                                         ||
|---------------------------------------------------------------------------------------------------------------------|-----------------------------------|
| [PixelCopy.Request.Builder](https://developer.android.com/reference/kotlin/android/view/PixelCopy.Request.Builder#) | this This value cannot be `null`. |

### setSourceRect

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun setSourceRect(srcRect: Rect?): PixelCopy.Request.Builder
```

Sets the region of the source to copy from. By default, the entire source is copied to the output. If only a subset of the source is necessary to be copied, specifying a srcRect will improve performance by reducing the amount of data being copied.

|                                                                                                       Parameters                                                                                                       ||
|-----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `srcRect` | [Rect](https://developer.android.com/reference/kotlin/android/graphics/Rect.html#)?: The area of the source to read from. Null or empty will be treated to mean the entire source This value may be `null`. |

|                                                                         Return                                                                         ||
|---------------------------------------------------------------------------------------------------------------------|-----------------------------------|
| [PixelCopy.Request.Builder](https://developer.android.com/reference/kotlin/android/view/PixelCopy.Request.Builder#) | this This value cannot be `null`. |