CGContext Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Graphics context and primitives to draw in them.
public class CGContext : CoreFoundation.NativeObject
type CGContext = class
inherit NativeObject
- Inheritance
- Derived
Remarks
A CGContext is a Quartz 2D destination for drawing. It holds parameters and their states (set with functions such as SetFillColor(CGColor)) and device information (for instance, ConvertSizeToDeviceSpace(CGSize)). CGContexts may represent a screen area, a bitmap, a PDF document, or a printer.
There are a limited number of CGContexts available and application developer's should be conscientious about disposing of them after use. Generally, that means putting the drawing code in using blocks, as shown in the following example:
public override void Draw (CGRect rect)
{
base.Draw (rect);
using (var context = UIGraphics.GetCurrentContext ())
{
// draw a rectangle using a path
var myRectangleButtonPath = new CGPath ();
myRectangleButtonPath.AddRect (new CGRect (new CGPoint (100, 10), new CGPoint (200, 400)));
context.AddPath (myRectangleButtonPath);
context.DrawPath (CGPathDrawingMode.Stroke);
}
}
The example additionally shows the very common pattern of an overridden Draw(CGRect) method in a custom UIView and the use of GetImageFromCurrentImageContext() to retrieve the current CGContext on which to draw.
Properties
| Name | Description |
|---|---|
| Handle | (Inherited from DisposableObject) |
| InterpolationQuality |
A hint for the level of quality used when interpolating images (for example, when scaling). |
| Owns | (Inherited from DisposableObject) |
| TextMatrix |
Defines the transform between text space and user space. Independent of the CGContext's state. |
| TextPosition |
The location, in user space coordinates, at which to draw text. |
Methods
| Name | Description |
|---|---|
| AddArc(NFloat, NFloat, NFloat, NFloat, NFloat, Boolean) | |
| AddArcToPoint(NFloat, NFloat, NFloat, NFloat, NFloat) | |
| AddCurveToPoint(NFloat, NFloat, NFloat, NFloat, NFloat, NFloat) | |
| AddEllipseInRect(CGRect) |
Adds an ellipse that fits in the specified |
| AddLines(CGPoint[]) |
Adds the given lines to the current path. |
| AddLineToPoint(NFloat, NFloat) | |
| AddPath(CGPath) |
Adds the specified path to the current path. |
| AddQuadCurveToPoint(NFloat, NFloat, NFloat, NFloat) | |
| AddRect(CGRect) |
Adds a rectangular path to the current path. |
| AddRects(CGRect[]) |
Adds an array of rectangular paths to the current path. |
| AsBitmapContext() |
Casts the CGContext into a CGBitmapContext. |
| BeginPage(Nullable<CGRect>) | |
| BeginPath() |
Starts a new path in the graphics context. |
| BeginTransparencyLayer(CGRect, NSDictionary) | |
| BeginTransparencyLayer(NSDictionary) |
With EndTransparencyLayer(), encloses operations on a fully transparent layer. |
| ClearHandle() | (Inherited from DisposableObject) |
| ClearRect(CGRect) |
Paints the rectangle transparently. |
| Clip() |
Sets the current path of the graphics context to be the clipping path. |
| ClipToMask(CGRect, CGImage) | |
| ClipToRect(CGRect) |
Modifies the clipping path to be the intersection of the current path and the supplied rectangle. |
| ClipToRects(CGRect[]) |
Modifies the current clipping path to be the insersection of the current clipping path and the region specified by the supplied rectangles. |
| ClosePath() |
Closes and completes the current path. |
| ConcatCTM(CGAffineTransform) |
Concatenates the specified |
| ContextFillRects(CGRect[]) | |
| ConvertPointToUserSpace(CGPoint) |
Converts a point from device space coordinates to user space coordinates. |
| ConvertRectToDeviceSpace(CGRect) |
Converts a rectangle from user space coordinates to device space coordinates. |
| ConvertRectToUserSpace(CGRect) |
Converts a rectangle from device space coordinates to user space coordinates. |
| ConvertSizeToDeviceSpace(CGSize) |
Converts a size from user space coordinates to device space coordinates. |
| ConvertSizeToUserSpace(CGSize) |
Converts a size from device space coordinates to user space coordinates. |
| CopyPath() |
Returns a deep copy of the current path in the current context. |
| Dispose() | (Inherited from DisposableObject) |
| Dispose(Boolean) | (Inherited from NativeObject) |
| DrawConicGradient(CGGradient, CGPoint, NFloat) | |
| DrawImage(CGRect, CGImage) | |
| DrawImageApplyingToneMapping(CGRect, CGImage, CGToneMapping, CGToneMappingOptions) |
Draw the specified image onto the CGContext, applying the tone mapping and any tone mapping options. |
| DrawImageApplyingToneMapping(CGRect, CGImage, CGToneMapping, NSDictionary) |
Draw the specified image onto the CGContext, applying the tone mapping and any tone mapping options. |
| DrawLayer(CGLayer, CGPoint) |
Draws a layer into the graphics context at the specified point. |
| DrawLayer(CGLayer, CGRect) |
Draws a layer into the graphics context bounded by the specified rectangle. |
| DrawLinearGradient(CGGradient, CGPoint, CGPoint, CGGradientDrawingOptions) | |
| DrawPath(CGPathDrawingMode) |
Draws the CGContext's current path. |
| DrawPDFPage(CGPDFPage) |
Renders the specified PDF |
| DrawRadialGradient(CGGradient, CGPoint, NFloat, CGPoint, NFloat, CGGradientDrawingOptions) | |
| DrawShading(CGShading) |
Renders the specified |
| DrawTiledImage(CGRect, CGImage) | |
| EndPage() |
Called to indicate the end of a page in a page-based context. |
| EndTransparencyLayer() |
Indicates the end of a transparency layer. |
| EOClip() |
Modifies the current clipping path, using the Even-Odd rule. |
| EOFillPath() |
Fills the current path, using the Even-Odd rule. |
| Equals(Object) | (Inherited from DisposableObject) |
| FillEllipseInRect(CGRect) |
Paints the ellipse defined by |
| FillPath() |
Fills the current path, using Non-Zero Winding rule. |
| FillRect(CGRect) |
Paints the specified |
| Flush() |
Forces all pending drawing to be rendered. |
| GetCheckedHandle() | (Inherited from DisposableObject) |
| GetClipBoundingBox() |
The bounding box of the current clipping path. |
| GetCTM() |
Retrieves the current Context Transformation Matrix. |
| GetEdrTargetHeadroom() |
Get the EDR headroom that's used when rendering HDR content. |
| GetHashCode() | (Inherited from DisposableObject) |
| GetPathBoundingBox() |
Returns the bounding box for the current path. |
| GetPathCurrentPoint() |
The current point in the CGContext's path. |
| GetUserSpaceToDeviceSpaceTransform() |
The CGAffineTransform that maps user-space coordinates into device-space coordinates. |
| InitializeHandle(NativeHandle) | (Inherited from DisposableObject) |
| IsPathEmpty() |
Whether the current path contains any subpaths. |
| MoveTo(NFloat, NFloat) | |
| PathContainsPoint(CGPoint, CGPathDrawingMode) | |
| PointToDeviceSpace(CGPoint) |
Returns a new CGPoint that converts the user-space |
| Release() | |
| ReplacePathWithStrokedPath() |
Replaces the current path with the stroked version of the path, based on the stroke paremeters. |
| ResetClip() | |
| RestoreState() |
Sets the state of the CGContext to what it was when SaveState() was last called. |
| Retain() | |
| RotateCTM(NFloat) | |
| SaveState() |
Stores the state of the CGContext. (See RestoreState().) |
| ScaleCTM(NFloat, NFloat) | |
| SelectFont(String, NFloat, CGTextEncoding) | |
| SetAllowsAntialiasing(Boolean) |
Whether the context allows antialiasing. |
| SetAllowsFontSmoothing(Boolean) |
Whether the context allows font smoothing. |
| SetAllowsFontSubpixelQuantization(Boolean) |
Whether the context allows for glyphs to be drawn at subpixel locations. |
| SetAllowsSubpixelPositioning(Boolean) |
Whether the context allows for glyphs to be aligned other than to pixel boundaries. |
| SetAlpha(NFloat) | |
| SetBlendMode(CGBlendMode) |
Specifies the compositing mode. |
| SetCharacterSpacing(NFloat) | |
| SetEdrTargetHeadroom(Single) |
Get the EDR headroom that's used when rendering HDR content. |
| SetFillColor(CGColor) |
Sets the fill color to the specified CGColor. |
| SetFillColor(NFloat, NFloat, NFloat, NFloat, NFloat) | |
| SetFillColor(NFloat, NFloat, NFloat, NFloat) | |
| SetFillColor(NFloat, NFloat) | |
| SetFillColor(NFloat[]) | |
| SetFillColorSpace(CGColorSpace) |
Specifies the CGColorSpace to be used in the context. |
| SetFillPattern(CGPattern, NFloat[]) | |
| SetFlatness(NFloat) | |
| SetFont(CGFont) |
Sets the CGFont used to render text. |
| SetFontSize(NFloat) | |
| SetLineCap(CGLineCap) |
Sets the style for the ends of lines. |
| SetLineDash(NFloat, NFloat[], Int32) | |
| SetLineDash(NFloat, NFloat[]) | |
| SetLineJoin(CGLineJoin) |
Sets the way lines are joined. |
| SetLineWidth(NFloat) | |
| SetMiterLimit(NFloat) | |
| SetPatternPhase(CGSize) |
Translates the pattern prior to beginning to tile it. |
| SetRenderingIntent(CGColorRenderingIntent) |
How colors outside the destination color space are handled. |
| SetShadow(CGSize, NFloat, CGColor) | |
| SetShouldAntialias(Boolean) |
Used in conjunction with SetAllowsAntialiasing(Boolean) to enable or disable antialiasing. |
| SetShouldSmoothFonts(Boolean) |
Used in conjunction with SetAllowsFontSmoothing(Boolean) to enable or disable font smoothing. |
| SetShouldSubpixelPositionFonts(Boolean) |
Used in conjunction with SetAllowsSubpixelPositioning(Boolean) to enable or disable glyph alignment with pixels. |
| SetStrokeColor(CGColor) |
Sets the stroke color. |
| SetStrokeColor(NFloat, NFloat, NFloat, NFloat, NFloat) | |
| SetStrokeColor(NFloat, NFloat, NFloat, NFloat) | |
| SetStrokeColor(NFloat, NFloat) | |
| SetStrokeColor(NFloat[]) | |
| SetStrokeColorSpace(CGColorSpace) |
Sets the CGColorSpace to be used with SetStrokeColor(NFloat[]). |
| SetStrokePattern(CGPattern, NFloat[]) | |
| SetTextDrawingMode(CGTextDrawingMode) |
Specifies how glyphs should be rendered. |
| ShouldSubpixelQuantizeFonts(Boolean) |
With SetAllowsFontSubpixelQuantization(Boolean), determines whether fonts should be drawn at subpixel locations. |
| ShowGlyphs(UInt16[], Int32) |
This method has been deprecated in favor of CoreText. |
| ShowGlyphs(UInt16[]) |
This method has been deprecated in favor of CoreText. |
| ShowGlyphsAtPoint(NFloat, NFloat, UInt16[], Int32) | |
| ShowGlyphsAtPoint(NFloat, NFloat, UInt16[]) | |
| ShowGlyphsAtPositions(UInt16[], CGPoint[], Int32) | |
| ShowGlyphsWithAdvances(UInt16[], CGSize[], Int32) | |
| ShowText(Byte[], Int32) |
This method has been deprecated in favor of CoreText. |
| ShowText(Byte[]) |
This method has been deprecated in favor of CoreText. |
| ShowText(String, Int32) |
This method has been deprecated in favor of CoreText. |
| ShowText(String) |
This method has been deprecated in favor of CoreText. |
| ShowTextAtPoint(NFloat, NFloat, Byte[], Int32) | |
| ShowTextAtPoint(NFloat, NFloat, Byte[]) | |
| ShowTextAtPoint(NFloat, NFloat, String, Int32) | |
| ShowTextAtPoint(NFloat, NFloat, String) | |
| StrokeEllipseInRect(CGRect) |
Strokes the ellipse defined by |
| StrokeLineSegments(CGPoint[]) |
Strokes the lines defined by the pairs in |
| StrokePath() |
Strokes the current path. Afterwards, the current path is reset. |
| StrokeRect(CGRect) |
Strokes the specified |
| StrokeRectWithWidth(CGRect, NFloat) | |
| Synchronize() |
Marks a CGContext for update. |
| TranslateCTM(NFloat, NFloat) | |
Extension Methods
| Name | Description |
|---|---|
| GetHandle(INativeObject) | |
| GetNonNullHandle(INativeObject, String) | |