---
title: "withUnsafePixelBuffer(at:_:)"
framework: accelerate
role: symbol
role_heading: Instance Method
path: "accelerate/vimage/pixelbuffer/withunsafepixelbuffer(at:_:)"
---

# withUnsafePixelBuffer(at:_:)

Calls the given closure with the pixel buffer that references the individual plane at the given index.

## Declaration

```swift
func withUnsafePixelBuffer<R>(at index: Int, _ body: (vImage.PixelBuffer<Format.PlanarPixelFormat>) throws -> R) rethrows -> R
```

## Parameters

- `index`: The index of the plane.
- `body`: A closure with a doc://com.apple.accelerate/documentation/Accelerate/vImage/PixelBuffer parameter that points to the underlying pixel buffer at the given index.

## Return Value

Return Value The return value, if any, of the body closure parameter.

## Discussion

Discussion Use this function to access a single planar pixel buffer from a multiple-plane pixel buffer. For example, the following code converts the 8-bit pixels at plane 2 to 32-bit and writes the result to dest:  let src = vImage.PixelBuffer<vImage.Planar8x4>(size: vImage.Size(width: 32,                                                                   height: 64))

let dest = vImage.PixelBuffer<vImage.PlanarF>(size: src.size)

src.withUnsafePixelBuffer(at: 2) { vImageBuffer in

vImageBuffer.convert(to: dest)  }

## See Also

### Accessing component pixel buffers

- [withUnsafePixelBuffers(_:)](accelerate/vimage/pixelbuffer/withunsafepixelbuffers(_:).md)
