---
title: "copy(to:cvImageFormat:cgImageFormat:)"
framework: accelerate
role: symbol
role_heading: Instance Method
path: "accelerate/vimage/pixelbuffer/copy(to:cvimageformat:cgimageformat:)"
---

# copy(to:cvImageFormat:cgImageFormat:)

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

## Declaration

```swift
func copy(to cvPixelBuffer: CVPixelBuffer, cvImageFormat: vImageCVImageFormat, cgImageFormat: vImage_CGImageFormat) throws
```

## Parameters

- `cvPixelBuffer`: The destination Core Video pixel buffer.
- `cvImageFormat`: A doc://com.apple.accelerate/documentation/Accelerate/vImageCVImageFormat that specifies the pixel format of the destination buffer.
- `cgImageFormat`: The Core Graphics format of the source buffer.

## Discussion

Discussion The destination Core Video pixel buffer must be nonplanar and be the same size as the source buffer. The following code shows how to incorporate a vImage pixel buffer into a CIImageProcessorKernel instance. The code calls copy(to:cvImageFormat:cgImageFormat:) to write the result of a contast stretch operation to the processor kernel’s output. class ContrastStretchImageProcessorKernel: CIImageProcessorKernel {          static var cgImageFormat = vImage_CGImageFormat(         bitsPerComponent: 8,         bitsPerPixel: 32,         colorSpace: CGColorSpaceCreateDeviceRGB(),         bitmapInfo: CGBitmapInfo(rawValue: CGImageAlphaInfo.noneSkipLast.rawValue),         renderingIntent: .defaultIntent)!          static let cvImageFormat = vImageCVImageFormat.make(         format: .format32BGRA,         colorSpace: CGColorSpaceCreateDeviceRGB(),         alphaIsOpaqueHint: true)!

override class var outputFormat: CIFormat {         return CIFormat.BGRA8     }          override class func formatForInput(at input: Int32) -> CIFormat {         return CIFormat.BGRA8     }          override class func process(with inputs: [CIImageProcessorInput]?,                                 arguments: [String: Any]?,                                 output: CIImageProcessorOutput) throws {                  guard             let input = inputs?.first,             let inputPixelBuffer = input.pixelBuffer,             let outputPixelBuffer = output.pixelBuffer else {                 return             }             let buffer = try vImage.PixelBuffer(copying: inputPixelBuffer,                                             cvImageFormat: cvImageFormat,                                             cgImageFormat: &cgImageFormat,                                             pixelFormat: vImage.Interleaved8x4.self)                  buffer.contrastStretch(destination: buffer)                  try buffer.copy(to: outputPixelBuffer,                         cvImageFormat: cvImageFormat,                         cgImageFormat: cgImageFormat)     } }

## See Also

### Pixel buffer methods

- [copy(to:)](accelerate/vimage/pixelbuffer/copy(to:).md)
- [makeCGImage(cgImageFormat:)](accelerate/vimage/pixelbuffer/makecgimage(cgimageformat:).md)
- [withCVPixelBuffer(readOnly:body:)](accelerate/vimage/pixelbuffer/withcvpixelbuffer(readonly:body:).md)
