---
title: "vImageBuffer_CopyToCVPixelBuffer(_:_:_:_:_:_:)"
framework: accelerate
role: symbol
role_heading: Function
path: "accelerate/vimagebuffer_copytocvpixelbuffer(_:_:_:_:_:_:)"
---

# vImageBuffer_CopyToCVPixelBuffer(_:_:_:_:_:_:)

Copies the contents of a vImage buffer to a Core Video pixel buffer.

## Declaration

```swift
func vImageBuffer_CopyToCVPixelBuffer(_ buffer: UnsafePointer<vImage_Buffer>, _ bufferFormat: UnsafePointer<vImage_CGImageFormat>, _ cvPixelBuffer: CVPixelBuffer, _ cvImageFormat: vImageCVImageFormat!, _ backgroundColor: UnsafePointer<CGFloat>!, _ flags: vImage_Flags) -> vImage_Error
```

## Parameters

- `buffer`: The source vImage buffer.
- `bufferFormat`: A doc://com.apple.accelerate/documentation/Accelerate/vImage_CGImageFormat structure that specifies the image format of the doc://com.apple.accelerate/documentation/Accelerate/vImage_Buffer structure. If doc://com.apple.accelerate/documentation/Accelerate/vImage_CGImageFormat/colorSpace is nil, the function uses doc://com.apple.documentation/documentation/CoreGraphics/CGColorSpace/sRGB.
- `cvPixelBuffer`: The destination doc://com.apple.documentation/documentation/CoreVideo/CVPixelBuffer instance. It’s not necessary to lock the pixel buffer before calling this function.
- `cvImageFormat`: An optional doc://com.apple.accelerate/documentation/Accelerate/vImageCVImageFormat instance that specifies the pixel format of the source pixel buffer. If this parameter is nil, the function attempts to derive this information from the Core Video pixel buffer.
- `backgroundColor`: If the source image contains alpha information and the destination format doesn’t contain alpha information, this function flattens the source image against this parameter.
- `flags`: The options to use when performing the operation. If your code implements its own tiling or its own multithreading, pass doc://com.apple.accelerate/documentation/Accelerate/kvImageDoNotTile; otherwise, pass doc://com.apple.accelerate/documentation/Accelerate/kvImageNoFlags.

## Return Value

Return Value kvImageNoError; otherwise, one of the error codes in Data Types and Constants.

## Discussion

Discussion For compatibility with Core Video, vImage substitutes gamma 1/1.961 for kCVImageBufferTransferFunction_ITU_R_709_2 and substitutes the ITU-R BT.709-5 transfer function for kCVImageBufferTransferFunction_SMPTE_240M_1995. You can manually set the transfer function using vImageCreateRGBColorSpaceWithPrimariesAndTransferFunction(_:_:_:_:_:) and vImageCVImageFormat_SetColorSpace(_:_:) to avoid this substitution.
