---
title: "withCVPixelBuffer(readOnly:body:)"
framework: accelerate
role: symbol
role_heading: Instance Method
path: "accelerate/vimage/pixelbuffer/withcvpixelbuffer(readonly:body:)"
---

# withCVPixelBuffer(readOnly:body:)

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

## Declaration

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

Discussion Use this function to pass a vImage pixel buffer to other frameworks. For example, the following code creates a Core Image CIImage instance from a CVPixelBuffer that shares its underlying storage with a pixel buffer: 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` }

## See Also

### Pixel buffer methods

- [copy(to:)](accelerate/vimage/pixelbuffer/copy(to:).md)
- [copy(to:cvImageFormat:cgImageFormat:)](accelerate/vimage/pixelbuffer/copy(to:cvimageformat:cgimageformat:).md)
- [makeCGImage(cgImageFormat:)](accelerate/vimage/pixelbuffer/makecgimage(cgimageformat:).md)
