Graphics Reference
In-Depth Information
The kCAFilterNearest option is the crudest approach. As the name suggests, this
algorithm (known as nearest-neighbor filtering) just samples the nearest single pixel and
performs no color blending at all. This is very fast, and doesn't blur the image, but the
quality is noticeably worse for shrunken images, and magnified images become blocky and
pixelated.
In Figure 4.14, note how the bilinear image looks less distorted than the nearest-neighbor
version when shrunk to a small size, but when enlarged it looks blurrier. Contrast this with
Figure 4.15, where we've started with a very small image. In this instance, nearest-neighbor
does a better job of preserving the original pixels, whereas linear filtering turns them into a
blurry mess regardless of whether the image is minified or magnified.
Figure 4.15 For small images without diagonals, nearest-neighbor filtering is better.
Generally speaking, for very small images or larger images with sharp contrast and few
diagonal lines (for example, computer-generated images), nearest-neighbor scaling will
preserve contrast and may yield better results. But for most images, especially photographs
or images with diagonals or curves, nearest-neighbor will look appreciably worse than
linear filtering. To put it another way, linear filtering preserves the shape , and nearest-
neighbor filtering preserves the pixels .
Let's try a real-world example. We'll modify the clock project from Chapter 3 to display an
LCD-style digital readout instead of an analog clock face. The digits will be created using a
simple pixel font (a font where the characters are constructed from individual pixels rather
than vector shapes), stored as a single image and displayed using the sprite sheet technique
introduced in Chapter 2 (see Figure 4.16).
Search WWH ::




Custom Search