<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: -",
    "macOS: 10.15.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: -",
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Accelerate",
  "identifier" : "/documentation/Accelerate/vImage_Buffer/init(cgImage:format:flags:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Accelerate"
    ],
    "preciseIdentifier" : "s:So13vImage_BufferV10AccelerateE02cgA06format5flagsABSo10CGImageRefa_So01va1_G6FormatVAC01vA0O7OptionsVtKcfc"
  },
  "title" : "init(cgImage:format:flags:)"
}
-->

# init(cgImage:format:flags:)

Creates a new buffer with the contents of a Core Graphics image using the supplied image format.

```
init(cgImage: CGImage, format: vImage_CGImageFormat, flags options: vImage.Options = .noFlags) throws
```

## Parameters

`cgImage`

The source image.

`format`

The desired image format.

`options`

The options to use when performing the operation.

## Discussion

This function converts the source Core Graphics image that the `cgImage` parameter specifies to the format that the `format` parameter describes.

For example, the following code converts a color image to grayscale and initializes the vImage buffer with the planar monochrome image data:

```swift
let format = vImage_CGImageFormat(
    bitsPerComponent: 8,
    bitsPerPixel: 8,
    colorSpace: CGColorSpaceCreateDeviceGray(),
    bitmapInfo: CGBitmapInfo(rawValue: CGImageAlphaInfo.none.rawValue))!

// `cgImage` is a color image.
let buffer = try vImage_Buffer(cgImage: cgImage,
                               format: format)
```

---

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)