Chapter 4. Drawing and Imaging

The Application Kit has a diverse set of graphics classes. These classes range from NSQuickDrawView, which lets developers use legacy graphics code based on the QuickDraw APIs in their Cocoa application, to NSOpenGLView, which provides a way to display OpenGL-based 3D graphics. The focus of this chapter, however, is on the 2D drawing and imaging classes that provide a high-level interface to Mac OS X’s graphics system, Quartz. Table 4-1 enumerates the classes discussed in this chapter.

Table 4-1. Application Kit drawing and imaging classes

Quartz is the foundation of Cocoa’s 2D graphics capabilities. It provides many advanced graphics capabilities, including color management, path-based drawing, transparency, and anti-aliasing. It uses the same fundamental model of drawing as Adobe’s Portable Document Format (PDF).

Quartz is actually two individual pieces of software in Mac OS X—Quartz Compositor and Quartz 2D. The Quartz Compositor is the underlying system service responsible for drawing the graphical user interface to screen from sources such as Quartz 2D, QuickTime, OpenGL, and QuickDraw. Quartz 2D, on the other hand, is an Application Programming Interface (API) for drawing and manipulating 2D graphics. This chapter concentrates on Quartz 2D’s drawing functionality.

You can access the Quartz 2D API directly through the CoreGraphics framework, but it is far more convenient to use the Cocoa classes that provide an easy-to-use interface to Quartz, including NSBezierPath, NSView, NSImage, and NSGraphicsContext. These classes provide the functionality to render paths, text, and images to screen or to the printed page.