<!--
{
  "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/withUnsafePointerToVImageBuffer(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Accelerate"
    ],
    "preciseIdentifier" : "s:10Accelerate6vImageO11PixelBufferVA2A011SinglePlaneC6FormatRzrlE025withUnsafePointerToVImageD0yqd__qd__SPySo01vb1_D0VGKXEKlF"
  },
  "title" : "withUnsafePointerToVImageBuffer(_:)"
}
-->

# withUnsafePointerToVImageBuffer(_:)

Calls the given closure with an unsafe pointer to the underlying vImage buffer.

```
func withUnsafePointerToVImageBuffer<R>(_ body: (UnsafePointer<vImage_Buffer>) throws -> R) rethrows -> R
```

## Parameters

`body`

A closure with an unsafe pointer to a [`vImage_Buffer`](/documentation/Accelerate/vImage_Buffer) parameter that points to the underlying vImage buffer of the pixel buffer.

## Return Value

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

## Discussion

Use this function to incorporate pixel buffer based image processing code with existing vImage code. For example, the following code passes a pixel buffer to the C API [`vImageBufferFill_ARGB8888(_:_:_:)`](/documentation/Accelerate/vImageBufferFill_ARGB8888(_:_:_:)) routine:

```swift
 let src = vImage.PixelBuffer<vImage.Interleaved8x4>(size: vImage.Size(width: 128, height: 128))

 src.withUnsafePointerToVImageBuffer { vImageBufferPtr in
     _ = vImageBufferFill_ARGB8888(vImageBufferPtr,
                                   [0, 0, 0, 0],
                                   vImage_Flags(kvImageNoFlags))
 }
```

---

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)