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

# withUnsafeVImageBuffer(_:)

Calls the given closure with the underlying vImage buffer.

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

## Parameters

`body`

A closure with 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 accesses a pixel buffer’s underlying vImage buffer’s `rowBytes` property:

```swift
 let src = try vImage.PixelBuffer<vImage.Interleaved8x4>(cgImage: cgImage,
                                                         cgImageFormat: &cgImageFormat)

 src.withUnsafeVImageBuffer { vImageBuffer in
     print(vImageBuffer.rowBytes)
 }
```

---

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)