Class

NSGraphicsContext

An object that represents a graphics context.

Declaration

@interface NSGraphicsContext : NSObject

Overview

You can think of a graphics context as a destination to which drawing and graphics state operations are sent for execution. Each graphics context contains its own graphics environment and state.

The NSGraphicsContext class is an abstract superclass for destination-specific graphics contexts. You obtain instances of concrete subclasses with the class methods currentContext, graphicsContextWithAttributes:, graphicsContextWithBitmapImageRep:, graphicsContextWithCGContext:flipped:, and graphicsContextWithWindow:.

At any time there is the notion of the current context. The current context for the current thread may be set using setCurrentContext:.

Graphics contexts are maintained on a stack. You push a graphics context onto the stack by sending it a saveGraphicsState message, and pop it off the stack by sending it a restoreGraphicsState message. By sending restoreGraphicsState to a graphics context object you remove it from the stack, and the next graphics context on the stack becomes the current graphics context.

Topics

Creating a Graphics Context

+ graphicsContextWithAttributes:

Instantiates and returns an instance of NSGraphicsContext using the specified attributes.

+ graphicsContextWithBitmapImageRep:

Instantiates and returns a new graphics context using the supplied NSBitmapImageRep object as the context destination.

+ graphicsContextWithCGContext:flipped:

Creates a new graphics context from the specified Core Graphics context and the initial flipped state.

+ graphicsContextWithGraphicsPort:flipped:

Instantiates and returns a new graphics context from the given graphics port.

Deprecated
+ graphicsContextWithWindow:

Creates and returns a new graphics context for drawing into a window.

Managing the Current Context

currentContext

Returns the current graphics context of the current thread.

CGContext

The Core Graphics context, which is a low-level, platform-specific graphics context.

graphicsPort

The low-level, platform-specific graphics context represented by the graphic port.

Deprecated

Managing the Graphics State

+ setGraphicsState:

Makes the graphics context of the specified graphics state current, and resets graphics state.

Deprecated
+ restoreGraphicsState

Pops a graphics context from the per-thread stack, makes it current, and sends the context a restoreGraphicsState message.

- restoreGraphicsState

Removes the receiver’s graphics state from the top of the graphics state stack and makes the next graphics state the current graphics state.

+ saveGraphicsState

Saves the graphics state of the current graphics context.

- saveGraphicsState

Saves the current graphics state and creates a new graphics state on the top of the stack.

Testing the Drawing Destination

+ currentContextDrawingToScreen

Returns a Boolean value that indicates whether the current context is drawing to the screen.

drawingToScreen

A Boolean value indicating whether the drawing destination is the screen.

Getting Information About a Context

attributes

The attributes used to create this instance.

NSGraphicsContextAttributeKey

These constants are dictionary keys used by graphicsContextWithAttributes: and attributes.

NSGraphicsContextRepresentationFormatName

These constants are possible values for the NSGraphicsContextRepresentationFormatAttributeName key in a graphic context’s attribute dictionary.

flipped

A Boolean value indicating the receiver’s flipped state.

Flushing Graphics to the Context

- flushGraphics

Forces any buffered operations or data to be sent to the receiver’s destination.

Managing the Focus Stack

- focusStack

Returns the object used by the context to track the hierarchy of views with locked focus.

Deprecated
- setFocusStack:

Sets the object used by the receiver to track the hierarchy of views with locked focus.

Deprecated

Configuring Rendering Options

compositingOperation

The receiver’s global compositing operation setting.

NSCompositingOperation

Compositing operators, described in terms of having source and destination images, each having an opaque and transparent region.

imageInterpolation

A constant that specifies the receiver’s interpolation (image smoothing) behavior.

NSImageInterpolation

Interpolations used by the imageInterpolation property.

shouldAntialias

A Boolean value indicating whether the receiver uses antialiasing.

patternPhase

The amount to offset the pattern color when filling the receiver.

Getting the Core Image Context

CIContext

A CIContext object that you can use to render into the receiver.

Managing the Color Rendering Intent

colorRenderingIntent

The current rendering intent in the receiver’s graphics state.

NSColorRenderingIntent

Constants that specify how Cocoa should handle colors that are not located within the destination color space of a graphics context.

Relationships

Inherits From