An object that represents a graphics context.


@interface NSGraphicsContext : NSObject


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.


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.

+ graphicsContextWithWindow:

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

Managing the Current Context


Returns the current graphics context of the current thread.


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


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


Managing the Graphics State

+ setGraphicsState:

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

+ 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.


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

Getting Information About a Context


The attributes used to create this instance.


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


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


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.

- setFocusStack:

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


Configuring Rendering Options


The receiver’s global compositing operation setting.


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


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


Interpolations used by the imageInterpolation property.


A Boolean value indicating whether the receiver uses antialiasing.


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

Getting the Core Image Context


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

Managing the Color Rendering Intent


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


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


Inherits From