<!--
{
  "availability" : [
    "macOS: 10.5.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSBitmapImageRep/init(cgImage:)-7o5tz",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSBitmapImageRep(im)initWithCGImage:"
  },
  "title" : "init(cgImage:)"
}
-->

# init(cgImage:)

Returns a bitmap image representation from a Core Graphics image object.

```
init(cgImage: CGImage)
```

## Parameters

`cgImage`

A Core Graphics image object (an opaque type) from which to create the receiver. This opaque type is retained.

## Return Value

An [`NSBitmapImageRep`](/documentation/AppKit/NSBitmapImageRep) object initialized from the contents of the Core Graphics image.

## Discussion

If you use this method, you should treat the resulting bitmap [`NSBitmapImageRep`](/documentation/AppKit/NSBitmapImageRep) object as read only. Because it only retains the value in the `cgImage` parameter, rather than unpacking the data, accessing the pixel data requires the creation of a copy of that data in memory. Changes to that data are not saved back to the Core Graphics image.

## See Also

[`var cgImage: CGImage?`](/documentation/AppKit/NSBitmapImageRep/cgImage)

A Core Graphics image object based on the bitmap image representation’s data.



---

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)