<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: -",
    "macOS: 13.0.0 -",
    "tvOS: 16.0.0 -",
    "visionOS: -",
    "watchOS: 9.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Accelerate",
  "identifier" : "/documentation/Accelerate/vImage/PixelBuffer/withUnsafePixelBuffer(at:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Accelerate"
    ],
    "preciseIdentifier" : "s:10Accelerate6vImageO11PixelBufferVA2A013MultiplePlaneC6FormatRzrlE010withUnsafecD02at_qd__Si_qd__AEy_06PlanarcG0QzGKXEtKlF"
  },
  "title" : "withUnsafePixelBuffer(at:_:)"
}
-->

# withUnsafePixelBuffer(at:_:)

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

```
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 [`vImage.PixelBuffer`](/documentation/Accelerate/vImage/PixelBuffer) parameter that points to the underlying pixel buffer at the given index.

## Return Value

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

## 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`:

```swift
 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)
 }
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)