---
title: "init(cgImage:)"
framework: appkit
role: symbol
role_heading: Initializer
path: "appkit/nsbitmapimagerep/init(cgimage:)-7o5tz"
---

# init(cgImage:)

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

## Declaration

```swift
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

Return Value An NSBitmapImageRep object initialized from the contents of the Core Graphics image.

## Discussion

Discussion If you use this method, you should treat the resulting bitmap 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

### Related Documentation

- [cgImage](appkit/nsbitmapimagerep/cgimage.md)

### Creating Bitmap Representations of Images

- [imageReps(with:)](appkit/nsbitmapimagerep/imagereps(with:).md)
- [colorize(byMappingGray:to:blackMapping:whiteMapping:)](appkit/nsbitmapimagerep/colorize(bymappinggray:to:blackmapping:whitemapping:).md)
- [init(bitmapDataPlanes:pixelsWide:pixelsHigh:bitsPerSample:samplesPerPixel:hasAlpha:isPlanar:colorSpaceName:bitmapFormat:bytesPerRow:bitsPerPixel:)](appkit/nsbitmapimagerep/init(bitmapdataplanes:pixelswide:pixelshigh:bitspersample:samplesperpixel:hasalpha:isplanar:colorspacename:bitmapformat:bytesperrow:bitsperpixel:).md)
- [init(bitmapDataPlanes:pixelsWide:pixelsHigh:bitsPerSample:samplesPerPixel:hasAlpha:isPlanar:colorSpaceName:bytesPerRow:bitsPerPixel:)](appkit/nsbitmapimagerep/init(bitmapdataplanes:pixelswide:pixelshigh:bitspersample:samplesperpixel:hasalpha:isplanar:colorspacename:bytesperrow:bitsperpixel:).md)
- [init(ciImage:)](appkit/nsbitmapimagerep/init(ciimage:)-7bi19.md)
- [init(data:)](appkit/nsbitmapimagerep/init(data:).md)
- [init(forIncrementalLoad:)](appkit/nsbitmapimagerep/init(forincrementalload:).md)
- [init(focusedViewRect:)](appkit/nsbitmapimagerep/init(focusedviewrect:).md)
