<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 8.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Accelerate",
  "identifier" : "/documentation/Accelerate/vImageBuffer_InitWithCVPixelBuffer(_:_:_:_:_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Accelerate"
    ],
    "preciseIdentifier" : "c:@F@vImageBuffer_InitWithCVPixelBuffer"
  },
  "title" : "vImageBuffer_InitWithCVPixelBuffer(_:_:_:_:_:_:)"
}
-->

# vImageBuffer_InitWithCVPixelBuffer(_:_:_:_:_:_:)

Initializes a vImage buffer with a copy of the contents of a Core Video pixel buffer.

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

## Parameters

`buffer`

The destination empty [`vImage_Buffer`](/documentation/Accelerate/vImage_Buffer) structure. On return, the function allocates new memory to the buffer and sets the buffer’s size to match the <doc://com.apple.documentation/documentation/CoreVideo/CVPixelBuffer> instance’s dimensions.

`desiredFormat`

A [`vImage_CGImageFormat`](/documentation/Accelerate/vImage_CGImageFormat) structure that specifies the image format of the [`vImage_Buffer`](/documentation/Accelerate/vImage_Buffer) structure. If [`colorSpace`](/documentation/Accelerate/vImage_CGImageFormat/colorSpace) is `nil`, the function uses <doc://com.apple.documentation/documentation/CoreGraphics/CGColorSpace/sRGB>.

`cvPixelBuffer`

The source <doc://com.apple.documentation/documentation/CoreVideo/CVPixelBuffer> instance. It’s not necessary to lock the pixel buffer before calling this function.

`cvImageFormat`

An optional [`vImageCVImageFormat`](/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 [`kvImageDoNotTile`](/documentation/Accelerate/kvImageDoNotTile); otherwise, pass [`kvImageNoFlags`](/documentation/Accelerate/kvImageNoFlags).

    Pass [`kvImageNoAllocate`](/documentation/Accelerate/kvImageNoAllocate)     if the destination buffer references existing data.

    If the pixel buffer uses chrominance subsampling and you want vImage to use a higher quality, but a slower, resampling filter, set the [`kvImageHighQualityResampling`](/documentation/Accelerate/kvImageHighQualityResampling)     flag.

## Return Value

[`kvImageNoError`](/documentation/Accelerate/kvImageNoError); otherwise, one of the error codes in <doc://com.apple.documentation/documentation/Accelerate/data-types-and-constants>.

## Discussion

Some Core Video pixel buffers and image formats have incompletely specified color information that prevents [`vImageBuffer_InitWithCVPixelBuffer(_:_:_:_:_:_:)`](/documentation/Accelerate/vImageBuffer_InitWithCVPixelBuffer(_:_:_:_:_:_:)) from performing the conversion. In this situation, the function returns one of the format errors below. To proceed, create a [`vImageCVImageFormat`](/documentation/Accelerate/vImageCVImageFormat) instance, add the missing information, and pass the image format instance as the `cvImageFormat` parameter to this function. It’s possible that more than one piece of information is missing.

- [`kvImageCVImageFormat_ConversionMatrix`](/documentation/Accelerate/kvImageCVImageFormat_ConversionMatrix): The conversion matrix is missing from the `cvPixelBuffer` or the `vImageCVImageFormat`. Use the [`vImageCVImageFormat_CopyConversionMatrix(_:_:_:)`](/documentation/Accelerate/vImageCVImageFormat_CopyConversionMatrix(_:_:_:)) function to copy a conversion matrix to an image format.
- [`kvImageCVImageFormat_ChromaSiting`](/documentation/Accelerate/kvImageCVImageFormat_ChromaSiting): The chrominance siting information is missing from the `cvPixelBuffer` or the `vImageCVImageFormat`. Use [`vImageCVImageFormat_SetChromaSiting(_:_:)`](/documentation/Accelerate/vImageCVImageFormat_SetChromaSiting(_:_:)) to set the chrominance siting on an image format.
- [`kvImageCVImageFormat_ColorSpace`](/documentation/Accelerate/kvImageCVImageFormat_ColorSpace): The color space that contains primaries and transfer function is missing from the `cvPixelBuffer` or the `vImageCVImageFormat`. Use [`vImageCVImageFormat_SetColorSpace(_:_:)`](/documentation/Accelerate/vImageCVImageFormat_SetColorSpace(_:_:)) to set the color space on an image format.

## Discussion

For compatibility with Core Video, vImage substitutes gamma `1/1.961` for <doc://com.apple.documentation/documentation/CoreVideo/kCVImageBufferTransferFunction_ITU_R_709_2> and substitutes the ITU-R BT.709-5 transfer function for <doc://com.apple.documentation/documentation/CoreVideo/kCVImageBufferTransferFunction_SMPTE_240M_1995>. You can manually set the transfer function using [`vImageCreateRGBColorSpaceWithPrimariesAndTransferFunction(_:_:_:_:_:)`](/documentation/Accelerate/vImageCreateRGBColorSpaceWithPrimariesAndTransferFunction(_:_:_:_:_:)) and [`vImageCVImageFormat_SetColorSpace(_:_:)`](/documentation/Accelerate/vImageCVImageFormat_SetColorSpace(_:_:)) to avoid this substitution.

---

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)