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

# withCVPixelBuffer(readOnly:body:)

Calls the given closure with a locked 32-bit BGRA Core Video Pixel Buffer.

```
func withCVPixelBuffer(readOnly: Bool, body: (CVPixelBuffer) -> Void)
```

## Parameters

`readOnly`

A Boolean value that specifies whether the function locks the <doc://com.apple.documentation/documentation/CoreVideo/CVPixelBuffer> with the <doc://com.apple.documentation/documentation/CoreVideo/CVPixelBufferLockFlags/readOnly> flag. If the closure doesn’t modify the data, set this parameter to `true`.

`body`

A closure with a <doc://com.apple.documentation/documentation/CoreVideo/CVPixelBuffer> parameter that points to the underlying pixel buffer image data.

## Discussion

Use this function to pass a vImage pixel buffer to other frameworks. For example, the following code creates a Core Image <doc://com.apple.documentation/documentation/CoreImage/CIImage> instance from a <doc://com.apple.documentation/documentation/CoreVideo/CVPixelBuffer> that shares its underlying storage with a pixel buffer:

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

src.withCVPixelBuffer(readOnly: false) { cvPixelBuffer in

    let ciImage = CIImage(cvImageBuffer: cvPixelBuffer)

    // Core Image workflow using `ciImage`
}
```

---

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)