---
title: "createCGImage(_:from:)"
framework: coreimage
role: symbol
role_heading: Instance Method
path: "coreimage/cicontext/createcgimage(_:from:)"
---

# createCGImage(_:from:)

Creates a Core Graphics image from a region of a Core Image image instance.

## Declaration

```swift
func createCGImage(_ image: CIImage, from fromRect: CGRect) -> CGImage?
```

## Parameters

- `image`: A doc://com.apple.coreimage/documentation/CoreImage/CIImage image instance for which to create a CGImage.
- `fromRect`: The CGRect region of the image to use. This region relative to the cartesean coordinate system of image. This region will be intersected with integralized and intersected with image.extent.

## Return Value

Return Value  Returns a new CGImage instance. You are responsible for releasing the returned image when you no longer need it. The returned value will be null if the extent is empty or too big.

## Discussion

Discussion The color space of the created CGImage will be sRGB unless the receiving CIContext was created with a kCIContextOutputColorSpace option. Normally the pixel format of the created CGImage will be 8 bits-per-component. It will be 16 bits-per-component float if the above color space is HDR.

## See Also

### Rendering Images

- [createCGImage(_:from:format:colorSpace:)](coreimage/cicontext/createcgimage(_:from:format:colorspace:).md)
- [createCGImage(_:from:format:colorSpace:deferred:)](coreimage/cicontext/createcgimage(_:from:format:colorspace:deferred:).md)
- [render(_:toBitmap:rowBytes:bounds:format:colorSpace:)](coreimage/cicontext/render(_:tobitmap:rowbytes:bounds:format:colorspace:).md)
- [render(_:to:)](coreimage/cicontext/render(_:to:).md)
- [render(_:to:bounds:colorSpace:)](coreimage/cicontext/render(_:to:bounds:colorspace:)-2k8l2.md)
- [render(_:to:bounds:colorSpace:)](coreimage/cicontext/render(_:to:bounds:colorspace:)-54b9l.md)
- [render(_:to:commandBuffer:bounds:colorSpace:)](coreimage/cicontext/render(_:to:commandbuffer:bounds:colorspace:).md)
