---
title: "withUnsafePixelBuffers(_:)"
framework: accelerate
role: symbol
role_heading: Instance Method
path: "accelerate/vimage/pixelbuffer/withunsafepixelbuffers(_:)"
---

# withUnsafePixelBuffers(_:)

Calls the given closure with the array of pixel buffers that reference the individual planes.

## Declaration

```swift
func withUnsafePixelBuffers<R>(_ body: ([vImage.PixelBuffer<Format.PlanarPixelFormat>]) throws -> R) rethrows -> R
```

## Parameters

- `body`: A closure with an array doc://com.apple.accelerate/documentation/Accelerate/vImage/PixelBuffer parameter that points to the underlying pixel buffers.

## Return Value

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

## Discussion

Discussion Use this function to access each individual planar pixel buffer of a multiple-plane pixel buffer. For example, the following code initializes a 4-channel interleaved pixel buffer from the first three pixel buffers of a 4-channel multiple-plane pixel buffer:  let src = vImage.PixelBuffer<vImage.Planar8x4>(size: vImage.Size(width: 32,                                                                   height: 64))

src.withUnsafePixelBuffers { overlaySource8x4PixelBuffers in

let dest = vImage.PixelBuffer<vImage.Interleaved8x3>(planarBuffers: [          overlaySource8x4PixelBuffers[0],          overlaySource8x4PixelBuffers[1],          overlaySource8x4PixelBuffers[2]      ])  }

## See Also

### Accessing component pixel buffers

- [withUnsafePixelBuffer(at:_:)](accelerate/vimage/pixelbuffer/withunsafepixelbuffer(at:_:).md)
