---
title: "init(cgImage:size:)"
framework: appkit
role: symbol
role_heading: Initializer
path: "appkit/nsimage/init(cgimage:size:)-8oznv"
---

# init(cgImage:size:)

Creates a new image using the contents of the provided image.

## Declaration

```swift
convenience init(cgImage: CGImage, size: NSSize)
```

## Parameters

- `cgImage`: The source image.
- `size`: The size of the new image. Use doc://com.apple.documentation/documentation/CoreFoundation/CGSize/zero, or doc://com.apple.documentation/documentation/Foundation/NSZeroSize in Objective-C, to have the new image adopt the pixel dimensions of the source image.

## Discussion

Discussion Don’t assume anything about the image, other than drawing it is equivalent to drawing the source image. This is not a designated initializer.

## See Also

### Creating Images from Existing Data

- [init(data:)](appkit/nsimage/init(data:).md)
- [init(dataIgnoringOrientation:)](appkit/nsimage/init(dataignoringorientation:).md)
- [init(pasteboard:)](appkit/nsimage/init(pasteboard:).md)
- [init(coder:)](appkit/nsimage/init(coder:).md)
