Chapter 13. Shadings and Patterns


The shadings and patterns in Quartz 2D are powerful tools for creating popular graphic effects. The first, shadings, allows you to create a smooth blend of color based on a function that you specify. Figure 13.1 presents examples of several shadings.

Figure 13.1. Shading Examples


Figure 13.1 uses some paths as clipping areas and drawn shadings inside of them. Out of necessity, all of the shadings in Figure 13.2 use grays. They could, just as easily, be in any color space that Quartz 2D supports.

Figure 13.2. An Example of a Pattern and Its Cell


A pattern is an efficient way to draw a single, repeated image. Your application draws a single, rectangular cell and Quartz 2D will tile that pattern on the drawing plane for you. You can transform the cell so your patterns can tile with just about any parallelogram. Figure 13.2 shows a rectangle filled with a simple pattern and the cell that created it.

Quartz 2D can generate the same effects that result from drawing patterns and shadings in other ways. An axial (a.k.a. linear) shading might be approximated with a series of multi-colored lines or rectangles. Careful use of transformations and a lot of drawing could easily replace a pattern. However, Quartz can draw shadings and patterns much more efficiently than either of these approximations.

For example, reproducing a pattern by drawing hundreds of copies of a graphic into a PDF context would lead to each copy adding to the size of the PDF. The PDF specification defines its own pattern primitive, which allows it to store a single copy of the pattern cell and some information about how to apply that cell to create the pattern. When drawing shading with lines or rectangles to a bitmap display, the drawing will likely show obvious bands of color instead of a smooth gradient. Quartz 2D can draw the shading at the pixel level and make the colors change smoothly.

This chapter explores both shadings and patterns and examines how to create the Core Graphics objects that represent these drawing elements, as well as discusses some of the performance issues associated with using them.




Quartz 2D Graphics for Mac OS X Developers
Quartz 2D Graphics for Mac OS X Developers
ISBN: 0321336631
EAN: 2147483647
Year: 2006
Pages: 100

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net