A graphics context is an opaque data type (CGContextRef) that encapsulates the information Quartz uses to draw images to an output device, such as a PDF file, a bitmap, or a window on a display. The information inside a graphics context includes graphics drawing parameters and a device-specific representation of the paint on the page. All objects in Quartz are drawn to, or contained by, a graphics context.
You can think of a graphics context as a drawing destination, as shown in Figure 1-3. When you draw with Quartz, all device-specific characteristics are contained within the specific type of graphics context you use. In other words, you can draw the same image to a different device simply by providing a different graphics context to the same sequence of Quartz drawing routines. You do not need to perform any device-specific calculations; Quartz does it for you.
These graphics contexts are available to your application:
A bitmap graphics context allows you to paint RGB colors, CMYK colors, or grayscale into a bitmap. A bitmap is a rectangular array (or raster) of pixels, each pixel representing a point in an image. Bitmap images are also called sampled images. The CMYK bitmap graphics context is available starting with Mac OS X v10.3. See “Creating a Bitmap Graphics Context.”
A PDF graphics context allows you to create a PDF file. In a PDF file, your drawing is preserved as a sequence of commands. There are some significant differences between PDF files and bitmaps:
PDF files, unlike bitmaps, may contain more than one page.
When you draw a page from a PDF file on a different device, the resulting image is optimized for the display characteristics of that device.
PDF files are resolution independent by nature—the size at which they are drawn can be increased or decreased infinitely without sacrificing image detail. The user-perceived quality of a bitmap image is tied to the resolution at which the bitmap is intended to be viewed.
A window graphics context is a bitmap graphics context that you can use to draw into a window. Note that because Quartz 2D is a graphics engine and not a window management system, you use one of the Mac OS X application frameworks to obtain a graphics context for a window. See “Creating a Window Graphics Context” for information on how to obtain a graphics context in Carbon and Cocoa applications.
A layer context (CGLayerRef) is an offscreen drawing destination designed for optimal performance. Introduced in Mac OS X v10.4, a layer context is a much better choice for offscreen drawing than a bitmap graphics context. See “CGLayer Drawing.”
A PostScript graphics context is managed by the printing framework. See “Obtaining a Graphics Context for Printing” for more information.
As of Mac OS X v10.4, Quartz has CGLayer objects, which are drawing layers that are associated with a graphics context. Drawing to a layer destination improves performance for certain types of drawing. For more information, see “CGLayer Drawing.”
Last updated: 2007-12-11