<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreGraphics",
  "identifier" : "/documentation/CoreGraphics/CGContext",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Core Graphics"
    ],
    "preciseIdentifier" : "c:@T@CGContextRef"
  },
  "title" : "CGContext"
}
-->

# CGContext

A Quartz 2D drawing environment.

```
class CGContext
```

## Overview

A `CGContext` instance represents a Quartz 2D drawing destination. A graphics context contains drawing parameters and all device-specific information needed to render the paint on a page to the destination, whether the destination is a window in an application, a bitmap image, a PDF document, or a printer.

## Topics

### Creating Bitmap Graphics Contexts

[`CGBitmapContextReleaseDataCallback`](/documentation/CoreGraphics/CGBitmapContextReleaseDataCallback)

A callback function used to release data associate with the bitmap context.

### Creating PDF Graphics Contexts

[`init(_:mediaBox:_:)`](/documentation/CoreGraphics/CGContext/init(_:mediaBox:_:))

Creates a URL-based PDF graphics context.

[`init(consumer:mediaBox:_:)`](/documentation/CoreGraphics/CGContext/init(consumer:mediaBox:_:))

Creates a PDF graphics context.

[Auxiliary Dictionary Keys](/documentation/CoreGraphics/auxiliary-dictionary-keys)

Keys for the auxiliary info dictionary you specify when creating a PDF context.

### Retaining and Releasing Graphics Contexts

[`CGContextRelease`](/documentation/CoreGraphics/CGContextRelease)

Decrements the retain count of a graphics context.

[`CGContextRetain`](/documentation/CoreGraphics/CGContextRetain)

Increments the retain count of a graphics context.

### Converting Between Coordinate Spaces

[`userSpaceToDeviceSpaceTransform`](/documentation/CoreGraphics/CGContext/userSpaceToDeviceSpaceTransform)

Returns an affine transform that maps user space coordinates to device space coordinates.

[`convertToDeviceSpace(_:)`](/documentation/CoreGraphics/CGContext/convertToDeviceSpace(_:)-53m7u)

Returns a point that is transformed from user space coordinates to device space coordinates.

[`convertToUserSpace(_:)`](/documentation/CoreGraphics/CGContext/convertToUserSpace(_:)-3mtg3)

Returns a point that is transformed from device space coordinates to user space coordinates.

[`convertToDeviceSpace(_:)`](/documentation/CoreGraphics/CGContext/convertToDeviceSpace(_:)-91x5g)

Returns a rectangle that is transformed from user space coordinate to device space coordinates.

[`convertToUserSpace(_:)`](/documentation/CoreGraphics/CGContext/convertToUserSpace(_:)-1hk5r)

Returns a rectangle that is transformed from device space coordinate to user space coordinates.

[`convertToDeviceSpace(_:)`](/documentation/CoreGraphics/CGContext/convertToDeviceSpace(_:)-224h2)

Returns a size that is transformed from user space coordinates to device space coordinates.

[`convertToUserSpace(_:)`](/documentation/CoreGraphics/CGContext/convertToUserSpace(_:)-693ur)

Returns a size that is transformed from device space coordinates to user space coordinates.

### Constructing a Current Graphics Path

[`beginPath()`](/documentation/CoreGraphics/CGContext/beginPath())

Creates a new empty path in a graphics context.

[`move(to:)`](/documentation/CoreGraphics/CGContext/move(to:))

Begins a new subpath at the specified point.

[`CGContextMoveToPoint`](/documentation/CoreGraphics/CGContextMoveToPoint)

Begins a new subpath at the point you specify.

[`addLine(to:)`](/documentation/CoreGraphics/CGContext/addLine(to:))

Appends a straight line segment from the current point to the specified point.

[`CGContextAddLineToPoint`](/documentation/CoreGraphics/CGContextAddLineToPoint)

Appends a straight line segment from the current point to the provided point .

[`addLines(between:)`](/documentation/CoreGraphics/CGContext/addLines(between:))

Adds a sequence of connected straight-line segments to the current path.

[`CGContextAddLines`](/documentation/CoreGraphics/CGContextAddLines)

Adds a sequence of connected straight-line segments to the current path.

[`addRect(_:)`](/documentation/CoreGraphics/CGContext/addRect(_:))

Adds a rectangular path to the current path.

[`addRects(_:)`](/documentation/CoreGraphics/CGContext/addRects(_:))

Adds a set of rectangular paths to the current path.

[`CGContextAddRects`](/documentation/CoreGraphics/CGContextAddRects)

Adds a set of rectangular paths to the current path.

[`addEllipse(in:)`](/documentation/CoreGraphics/CGContext/addEllipse(in:))

Adds an ellipse that fits inside the specified rectangle.

[`addArc(center:radius:startAngle:endAngle:clockwise:)`](/documentation/CoreGraphics/CGContext/addArc(center:radius:startAngle:endAngle:clockwise:))

Adds an arc of a circle to the current path, specified with a radius and angles.

[`CGContextAddArc`](/documentation/CoreGraphics/CGContextAddArc)

Adds an arc of a circle to the current path, possibly preceded by a straight line segment

[`addArc(tangent1End:tangent2End:radius:)`](/documentation/CoreGraphics/CGContext/addArc(tangent1End:tangent2End:radius:))

Adds an arc of a circle to the current path, specified with a radius and two tangent lines.

[`CGContextAddArcToPoint`](/documentation/CoreGraphics/CGContextAddArcToPoint)

Adds an arc of a circle to the current path, using a radius and tangent points.

[`addCurve(to:control1:control2:)`](/documentation/CoreGraphics/CGContext/addCurve(to:control1:control2:))

Adds a cubic Bézier curve to the current path, with the specified end point and control points.

[`CGContextAddCurveToPoint`](/documentation/CoreGraphics/CGContextAddCurveToPoint)

Appends a cubic Bézier curve from the current point, using the provided control points and end point .

[`addQuadCurve(to:control:)`](/documentation/CoreGraphics/CGContext/addQuadCurve(to:control:))

Adds a quadratic Bézier curve to the current path, with the specified end point and control point.

[`CGContextAddQuadCurveToPoint`](/documentation/CoreGraphics/CGContextAddQuadCurveToPoint)

Appends a quadratic Bézier curve from the current point, using a control point and an end point you specify.

[`addPath(_:)`](/documentation/CoreGraphics/CGContext/addPath(_:))

Adds a previously created path object to the current path in a graphics context.

[`closePath()`](/documentation/CoreGraphics/CGContext/closePath())

Closes and terminates the current path’s subpath.

[`path`](/documentation/CoreGraphics/CGContext/path)

Returns a path object built from the current path information in a graphics context.

[`replacePathWithStrokedPath()`](/documentation/CoreGraphics/CGContext/replacePathWithStrokedPath())

Replaces the path in the graphics context with the stroked version of the path.

### Examining the Current Graphics Path

[`boundingBoxOfPath`](/documentation/CoreGraphics/CGContext/boundingBoxOfPath)

Returns the smallest rectangle that contains the current path.

[`currentPointOfPath`](/documentation/CoreGraphics/CGContext/currentPointOfPath)

Returns the current point in a non-empty path.

[`isPathEmpty`](/documentation/CoreGraphics/CGContext/isPathEmpty)

Indicates whether the current path contains any subpaths.

[`pathContains(_:mode:)`](/documentation/CoreGraphics/CGContext/pathContains(_:mode:))

Checks to see whether the specified point is contained in the current path.

### Drawing the Current Graphics Path

[`drawPath(using:)`](/documentation/CoreGraphics/CGContext/drawPath(using:))

Draws the current path using the provided drawing mode.

[`CGPathDrawingMode`](/documentation/CoreGraphics/CGPathDrawingMode)

Options for rendering a path.

[`fillPath(using:)`](/documentation/CoreGraphics/CGContext/fillPath(using:))

Paints the area within the current path, as determined by the specified fill rule.

[`CGContextEOFillPath`](/documentation/CoreGraphics/CGContextEOFillPath)

Paints the area within the current path, using the even-odd fill rule.

[`CGContextFillPath`](/documentation/CoreGraphics/CGContextFillPath)

Paints the area within the current path, using the nonzero winding number rule.

[`strokePath()`](/documentation/CoreGraphics/CGContext/strokePath())

Paints a line along the current path.

### Drawing Shapes

[`clear(_:)`](/documentation/CoreGraphics/CGContext/clear(_:))

Paints a transparent rectangle.

[`fill(_:)`](/documentation/CoreGraphics/CGContext/fill(_:)-7a0rk)

Paints the area contained within the provided rectangle, using the fill color in the current graphics state.

[`fill(_:)`](/documentation/CoreGraphics/CGContext/fill(_:)-6jc4y)

Paints the areas contained within the provided rectangles, using the fill color in the current graphics state.

[`CGContextFillRects`](/documentation/CoreGraphics/CGContextFillRects)

Paints the areas contained within the provided rectangles, using the fill color in the current graphics state.

[`fillEllipse(in:)`](/documentation/CoreGraphics/CGContext/fillEllipse(in:))

Paints the area of the ellipse that fits inside the provided rectangle, using the fill color in the current graphics state.

[`stroke(_:)`](/documentation/CoreGraphics/CGContext/stroke(_:))

Paints a rectangular path.

[`stroke(_:width:)`](/documentation/CoreGraphics/CGContext/stroke(_:width:))

Paints a rectangular path, using the specified line width.

[`strokeEllipse(in:)`](/documentation/CoreGraphics/CGContext/strokeEllipse(in:))

Strokes an ellipse that fits inside the specified rectangle.

[`strokeLineSegments(between:)`](/documentation/CoreGraphics/CGContext/strokeLineSegments(between:))

Strokes a sequence of line segments.

[`CGContextStrokeLineSegments`](/documentation/CoreGraphics/CGContextStrokeLineSegments)

Strokes a sequence of line segments.

### Drawing Images and PDF Content

[`CGContextDrawTiledImage`](/documentation/CoreGraphics/CGContextDrawTiledImage)

Repeatedly draws an image, scaled to the provided rectangle, to fill the current clip region.

[`CGContextDrawImage`](/documentation/CoreGraphics/CGContextDrawImage)

Draws an image into a graphics context.

[`draw(_:in:byTiling:)`](/documentation/CoreGraphics/CGContext/draw(_:in:byTiling:))

Draws an image in the specified area.

[`drawPDFPage(_:)`](/documentation/CoreGraphics/CGContext/drawPDFPage(_:))

Draws the content of a PDF page into the current graphics context.

[`interpolationQuality`](/documentation/CoreGraphics/CGContext/interpolationQuality)

Returns the current level of interpolation quality for a graphics context.

[`CGContextSetInterpolationQuality`](/documentation/CoreGraphics/CGContextSetInterpolationQuality)

Sets the level of interpolation quality for a graphics context.

[`CGInterpolationQuality`](/documentation/CoreGraphics/CGInterpolationQuality)

Levels of interpolation quality for rendering an image.

### Drawing Gradients and Shadings

[`drawLinearGradient(_:start:end:options:)`](/documentation/CoreGraphics/CGContext/drawLinearGradient(_:start:end:options:))

Paints a gradient fill that varies along the line defined by the provided starting and ending points.

[`drawRadialGradient(_:startCenter:startRadius:endCenter:endRadius:options:)`](/documentation/CoreGraphics/CGContext/drawRadialGradient(_:startCenter:startRadius:endCenter:endRadius:options:))

Paints a gradient fill that varies along the area defined by the provided starting and ending circles.

[`CGGradientDrawingOptions`](/documentation/CoreGraphics/CGGradientDrawingOptions)

Drawing locations for gradients.

[`drawShading(_:)`](/documentation/CoreGraphics/CGContext/drawShading(_:))

Fills the clipping path of a context with the specified shading.

### Drawing Text

[`textMatrix`](/documentation/CoreGraphics/CGContext/textMatrix)

Returns the current text matrix.

[`CGContextSetTextMatrix`](/documentation/CoreGraphics/CGContextSetTextMatrix)

Sets the current text matrix.

[`textPosition`](/documentation/CoreGraphics/CGContext/textPosition)

[`CGContextSetTextPosition`](/documentation/CoreGraphics/CGContextSetTextPosition)

Sets the location at which text is drawn.

[`CGContextGetTextPosition`](/documentation/CoreGraphics/CGContextGetTextPosition)

[`selectFont(name:size:textEncoding:)`](/documentation/CoreGraphics/CGContext/selectFont(name:size:textEncoding:))

Sets the font and font size in a graphics context.

[`setCharacterSpacing(_:)`](/documentation/CoreGraphics/CGContext/setCharacterSpacing(_:))

Sets the current character spacing.

[`setFont(_:)`](/documentation/CoreGraphics/CGContext/setFont(_:))

Sets the platform font in a graphics context.

[`setFontSize(_:)`](/documentation/CoreGraphics/CGContext/setFontSize(_:))

Sets the current font size.

[`setTextDrawingMode(_:)`](/documentation/CoreGraphics/CGContext/setTextDrawingMode(_:))

Sets the current text drawing mode.

[`setAllowsFontSmoothing(_:)`](/documentation/CoreGraphics/CGContext/setAllowsFontSmoothing(_:))

Sets whether or not to allow font smoothing for a graphics context.

[`setAllowsFontSubpixelPositioning(_:)`](/documentation/CoreGraphics/CGContext/setAllowsFontSubpixelPositioning(_:))

Sets whether or not to allow subpixel positioning for a graphics context.

[`setAllowsFontSubpixelQuantization(_:)`](/documentation/CoreGraphics/CGContext/setAllowsFontSubpixelQuantization(_:))

Sets whether or not to allow subpixel quantization for a graphics context.

[`setShouldSmoothFonts(_:)`](/documentation/CoreGraphics/CGContext/setShouldSmoothFonts(_:))

Enables or disables font smoothing in a graphics context.

[`setShouldSubpixelPositionFonts(_:)`](/documentation/CoreGraphics/CGContext/setShouldSubpixelPositionFonts(_:))

Enables or disables subpixel positioning in a graphics context.

[`setShouldSubpixelQuantizeFonts(_:)`](/documentation/CoreGraphics/CGContext/setShouldSubpixelQuantizeFonts(_:))

Enables or disables subpixel quantization in a graphics context.

[`showGlyphs(g:count:)`](/documentation/CoreGraphics/CGContext/showGlyphs(g:count:))

Displays an array of glyphs at the current text position.

[`showGlyphs(_:at:)`](/documentation/CoreGraphics/CGContext/showGlyphs(_:at:))

Draws a set of glyphs at a set of corresponding positions.

[`CGContextShowGlyphsAtPositions`](/documentation/CoreGraphics/CGContextShowGlyphsAtPositions)

Draws glyphs at the provided position.

[`showGlyphsAtPoint(x:y:glyphs:count:)`](/documentation/CoreGraphics/CGContext/showGlyphsAtPoint(x:y:glyphs:count:))

Displays an array of glyphs at a position you specify.

[`showGlyphsWithAdvances(glyphs:advances:count:)`](/documentation/CoreGraphics/CGContext/showGlyphsWithAdvances(glyphs:advances:count:))

Draws an array of glyphs with varying offsets.

[`showText(string:length:)`](/documentation/CoreGraphics/CGContext/showText(string:length:))

Displays a character array at the current text position, a point specified by the current text matrix.

[`showTextAtPoint(x:y:string:length:)`](/documentation/CoreGraphics/CGContext/showTextAtPoint(x:y:string:length:))

Displays a character string at a position you specify.

[`CGTextDrawingMode`](/documentation/CoreGraphics/CGTextDrawingMode)

Modes for rendering text.

### Drawing Core Graphics Layers

[`draw(_:at:)`](/documentation/CoreGraphics/CGContext/draw(_:at:))

Draws the contents of a layer object at the specified point.

[`CGContextDrawLayerAtPoint`](/documentation/CoreGraphics/CGContextDrawLayerAtPoint)

Draws the contents of a CGLayer object at the specified point.

[`draw(_:in:)`](/documentation/CoreGraphics/CGContext/draw(_:in:))

Draws the contents of a layer object into the specified rectangle.

[`CGContextDrawLayerInRect`](/documentation/CoreGraphics/CGContextDrawLayerInRect)

Draws the contents of a layer object into the specified rectangle.

### Setting Fill, Stroke, and Shadow Colors

[`setFillColor(_:)`](/documentation/CoreGraphics/CGContext/setFillColor(_:)-8lhn8)

Sets the current fill color in a graphics context, using a CGColor.

[`setFillColor(_:)`](/documentation/CoreGraphics/CGContext/setFillColor(_:)-756dy)

Sets the current fill color.

[`setFillColor(cyan:magenta:yellow:black:alpha:)`](/documentation/CoreGraphics/CGContext/setFillColor(cyan:magenta:yellow:black:alpha:))

Sets the current fill color to a value in the DeviceCMYK color space.

[`setFillColor(gray:alpha:)`](/documentation/CoreGraphics/CGContext/setFillColor(gray:alpha:))

Sets the current fill color to a value in the DeviceGray color space.

[`setFillColor(red:green:blue:alpha:)`](/documentation/CoreGraphics/CGContext/setFillColor(red:green:blue:alpha:))

Sets the current fill color to a value in the DeviceRGB color space.

[`setFillColorSpace(_:)`](/documentation/CoreGraphics/CGContext/setFillColorSpace(_:))

Sets the fill color space in a graphics context.

[`setShadow(offset:blur:)`](/documentation/CoreGraphics/CGContext/setShadow(offset:blur:))

Enables shadowing in a graphics context.

[`setShadow(offset:blur:color:)`](/documentation/CoreGraphics/CGContext/setShadow(offset:blur:color:))

Enables shadowing with color a graphics context.

[`setStrokeColor(_:)`](/documentation/CoreGraphics/CGContext/setStrokeColor(_:)-1sskg)

Sets the current stroke color in a context, using a CGColor.

[`setStrokeColor(_:)`](/documentation/CoreGraphics/CGContext/setStrokeColor(_:)-4pd8p)

Sets the current stroke color.

[`setStrokeColor(cyan:magenta:yellow:black:alpha:)`](/documentation/CoreGraphics/CGContext/setStrokeColor(cyan:magenta:yellow:black:alpha:))

Sets the current stroke color to a value in the DeviceCMYK color space.

[`setStrokeColor(gray:alpha:)`](/documentation/CoreGraphics/CGContext/setStrokeColor(gray:alpha:))

Sets the current stroke color to a value in the DeviceGray color space.

[`setStrokeColor(red:green:blue:alpha:)`](/documentation/CoreGraphics/CGContext/setStrokeColor(red:green:blue:alpha:))

Sets the current stroke color to a value in the DeviceRGB color space.

[`setStrokeColorSpace(_:)`](/documentation/CoreGraphics/CGContext/setStrokeColorSpace(_:))

Sets the stroke color space in a graphics context.

[`setStrokePattern(_:colorComponents:)`](/documentation/CoreGraphics/CGContext/setStrokePattern(_:colorComponents:))

Sets the stroke pattern in the specified graphics context.

[`setAlpha(_:)`](/documentation/CoreGraphics/CGContext/setAlpha(_:))

Sets the opacity level for objects drawn in a graphics context.

### Working with the Current Clipping Path

[`clip(using:)`](/documentation/CoreGraphics/CGContext/clip(using:))

Modifies the current clipping path.

[`clip(to:)`](/documentation/CoreGraphics/CGContext/clip(to:)-7cbwq)

Sets the clipping path to the intersection of the current clipping path with the area defined by the specified rectangle.

[`clip(to:)`](/documentation/CoreGraphics/CGContext/clip(to:)-2eg0)

Sets the clipping path to the intersection of the current clipping path with the region defined by an array of rectangles.

[`clip(to:mask:)`](/documentation/CoreGraphics/CGContext/clip(to:mask:))

Maps a mask into the specified rectangle and intersects it with the current clipping area of the graphics context.

[`boundingBoxOfClipPath`](/documentation/CoreGraphics/CGContext/boundingBoxOfClipPath)

Returns the bounding box of a clipping path.

[`CGContextClip`](/documentation/CoreGraphics/CGContextClip)

Modifies the current clipping path, using the nonzero winding number rule.

[`CGContextEOClip`](/documentation/CoreGraphics/CGContextEOClip)

Modifies the current clipping path, using the even-odd rule.

[`CGContextClipToRects`](/documentation/CoreGraphics/CGContextClipToRects)

Sets the clipping path to the intersection of the current clipping path with the region defined by an array of rectangles.

### Working with Transparency Layers

[`beginTransparencyLayer(in:auxiliaryInfo:)`](/documentation/CoreGraphics/CGContext/beginTransparencyLayer(in:auxiliaryInfo:))

Begins a transparency layer whose contents are bounded by the specified rectangle.

[`beginTransparencyLayer(auxiliaryInfo:)`](/documentation/CoreGraphics/CGContext/beginTransparencyLayer(auxiliaryInfo:))

Begins a transparency layer.

[`endTransparencyLayer()`](/documentation/CoreGraphics/CGContext/endTransparencyLayer())

Ends a transparency layer.

### Working with the Current Transformation Matrix

[`ctm`](/documentation/CoreGraphics/CGContext/ctm)

Returns the current transformation matrix.

[`rotate(by:)`](/documentation/CoreGraphics/CGContext/rotate(by:))

Rotates the user coordinate system in a context.

[`scaleBy(x:y:)`](/documentation/CoreGraphics/CGContext/scaleBy(x:y:))

Changes the scale of the user coordinate system in a context.

[`translateBy(x:y:)`](/documentation/CoreGraphics/CGContext/translateBy(x:y:))

Changes the origin of the user coordinate system in a context.

[`concatenate(_:)`](/documentation/CoreGraphics/CGContext/concatenate(_:))

Transforms the user coordinate system in a context using a specified matrix.

### Setting Path Drawing Options

[`setAllowsAntialiasing(_:)`](/documentation/CoreGraphics/CGContext/setAllowsAntialiasing(_:))

Sets whether or not to allow antialiasing for a graphics context.

[`setFlatness(_:)`](/documentation/CoreGraphics/CGContext/setFlatness(_:))

Sets the accuracy of curved paths in a graphics context.

[`setLineCap(_:)`](/documentation/CoreGraphics/CGContext/setLineCap(_:))

Sets the style for the endpoints of lines drawn in a graphics context.

[`setLineDash(phase:lengths:)`](/documentation/CoreGraphics/CGContext/setLineDash(phase:lengths:))

Sets the pattern for drawing dashed lines.

[`CGContextSetLineDash`](/documentation/CoreGraphics/CGContextSetLineDash)

Sets the pattern for dashed lines in a graphics context.

[`setLineJoin(_:)`](/documentation/CoreGraphics/CGContext/setLineJoin(_:))

Sets the style for the joins of connected lines in a graphics context.

[`setLineWidth(_:)`](/documentation/CoreGraphics/CGContext/setLineWidth(_:))

Sets the line width for a graphics context.

[`setMiterLimit(_:)`](/documentation/CoreGraphics/CGContext/setMiterLimit(_:))

Sets the miter limit for the joins of connected lines in a graphics context.

[`setPatternPhase(_:)`](/documentation/CoreGraphics/CGContext/setPatternPhase(_:))

Sets the pattern phase of a context.

[`setFillPattern(_:colorComponents:)`](/documentation/CoreGraphics/CGContext/setFillPattern(_:colorComponents:))

Sets the fill pattern in the specified graphics context.

[`setShouldAntialias(_:)`](/documentation/CoreGraphics/CGContext/setShouldAntialias(_:))

Sets antialiasing on or off for a graphics context.

### Saving and Restoring Graphics State

[`saveGState()`](/documentation/CoreGraphics/CGContext/saveGState())

Pushes a copy of the current graphics state onto the graphics state stack for the context.

[`restoreGState()`](/documentation/CoreGraphics/CGContext/restoreGState())

Sets the current graphics state to the state most recently saved.

### Managing a Graphics Context

[`flush()`](/documentation/CoreGraphics/CGContext/flush())

Forces all pending drawing operations in a window context to be rendered immediately to the destination device.

[`synchronize()`](/documentation/CoreGraphics/CGContext/synchronize())

Marks a window context for update.

[`setBlendMode(_:)`](/documentation/CoreGraphics/CGContext/setBlendMode(_:))

Sets how sample values are composited by a graphics context.

[`CGBlendMode`](/documentation/CoreGraphics/CGBlendMode)

Compositing operations for images.

[`setRenderingIntent(_:)`](/documentation/CoreGraphics/CGContext/setRenderingIntent(_:))

Sets the rendering intent in the current graphics state.

### Managing a Bitmap Graphics Context

These properties and methods are valid only when used with a `CGContext` object created with the initializers listed in [`Creating Bitmap Graphics Contexts`](/documentation/CoreGraphics/CGContext#Creating-Bitmap-Graphics-Contexts).

[`bitmapInfo`](/documentation/CoreGraphics/CGContext/bitmapInfo)

Obtains the bitmap information associated with a bitmap graphics context.

[`alphaInfo`](/documentation/CoreGraphics/CGContext/alphaInfo)

Returns the alpha information associated with the context, which indicates how a bitmap context handles the alpha component.

[`bitsPerComponent`](/documentation/CoreGraphics/CGContext/bitsPerComponent)

Returns the bits per component of a bitmap context.

[`bitsPerPixel`](/documentation/CoreGraphics/CGContext/bitsPerPixel)

Returns the bits per pixel of a bitmap context.

[`bytesPerRow`](/documentation/CoreGraphics/CGContext/bytesPerRow)

Returns the bytes per row of a bitmap context.

[`colorSpace`](/documentation/CoreGraphics/CGContext/colorSpace)

Returns the color space of a bitmap context.

[`data`](/documentation/CoreGraphics/CGContext/data)

Returns a pointer to the image data associated with a bitmap context.

[`height`](/documentation/CoreGraphics/CGContext/height)

Returns the height in pixels of a bitmap context.

[`width`](/documentation/CoreGraphics/CGContext/width)

Returns the width in pixels of a bitmap context.

[`makeImage()`](/documentation/CoreGraphics/CGContext/makeImage())

Creates and returns a CGImage from the pixel data in a bitmap graphics context.

### Managing a PDF Graphics Context

These methods are valid only when used with a `CGContext` object created with the initializers listed in [`Creating PDF Graphics Contexts`](/documentation/CoreGraphics/CGContext#Creating-PDF-Graphics-Contexts).

[`beginPDFPage(_:)`](/documentation/CoreGraphics/CGContext/beginPDFPage(_:))

Begins a new page in a PDF graphics context.

[`endPDFPage()`](/documentation/CoreGraphics/CGContext/endPDFPage())

Ends the current page in the PDF graphics context.

[`addDestination(_:at:)`](/documentation/CoreGraphics/CGContext/addDestination(_:at:))

Sets a destination to jump to when a point in the current page of a PDF graphics context is clicked.

[`setDestination(_:for:)`](/documentation/CoreGraphics/CGContext/setDestination(_:for:))

Sets a destination to jump to when a rectangle in the current PDF page is clicked.

[`setURL(_:for:)`](/documentation/CoreGraphics/CGContext/setURL(_:for:))

Sets the URL associated with a rectangle in a PDF graphics context.

[`addDocumentMetadata(_:)`](/documentation/CoreGraphics/CGContext/addDocumentMetadata(_:))

Associates custom metadata with the PDF document.

[`closePDF()`](/documentation/CoreGraphics/CGContext/closePDF())

Closes a PDF document.

### Managing a Page-Based Graphics Context

[`beginPage(mediaBox:)`](/documentation/CoreGraphics/CGContext/beginPage(mediaBox:))

Starts a new page in a page-based graphics context.

[`endPage()`](/documentation/CoreGraphics/CGContext/endPage())

Ends the current page in a page-based graphics context.

### Working with Core Foundation Types

[`typeID`](/documentation/CoreGraphics/CGContext/typeID)

Returns the type identifier for a graphics context.

### Constants

[`CGPathFillRule`](/documentation/CoreGraphics/CGPathFillRule)

Rules for determining which regions are interior to a path, used by the [`fillPath(using:)`](/documentation/CoreGraphics/CGContext/fillPath(using:)) and [`clip(using:)`](/documentation/CoreGraphics/CGContext/clip(using:)) methods.

[`CGTextEncoding`](/documentation/CoreGraphics/CGTextEncoding)

Text encodings for fonts.

### Instance Methods

[`draw(_:in:by:options:)`](/documentation/CoreGraphics/CGContext/draw(_:in:by:options:))

[`resetClip()`](/documentation/CoreGraphics/CGContext/resetClip())

[`setEDRTargetHeadroom(_:)`](/documentation/CoreGraphics/CGContext/setEDRTargetHeadroom(_:))

## See Also

  [Quartz 2D Programming Guide](https://developer.apple.com/library/archive/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/Introduction/Introduction.html#//apple_ref/doc/uid/TP30001066)



---

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)