Graphics Reference
In-Depth Information
Sometimes, however, it's necessary to display an image at a larger-than-actual or smaller-
than-actual size. Examples might include a thumbnail image of a person or avatar, or a very
large image that the user can pan and zoom. In these cases, it might not be practical to store
separate copies of the image for every size it might need to be displayed at.
When images are displayed at different sizes, an algorithm (known as a scaling filter ) is
applied to the pixels of the original image to generate the new pixels that will be displayed
onscreen.
There is no universally ideal algorithm for resizing an image. The approach depends on the
nature of the content being scaled, and whether you are scaling up or down. CALayer
offers a choice of three scaling filters to use when resizing images. These are represented
by the following string constants:
kCAFilterLinear
kCAFilterNearest
kCAFilterTrilinear
The default filter for both minification (shrinking an image) and magnification (expanding
an image) is kCAFilterLinear . This filter uses the bilinear filtering algorithm, which
yields good results under the majority of circumstances. Bilinear filtering works by
sampling multiple pixels to create the final value. This results in nice, smooth scaling, but
can make the image appear blurry if it scaled up by a large factor (see Figure 4.14).
The kCAFilterTrilinear option is very similar to kCAFilterLinear . There is no
visible difference between them in most cases, but trilinear filtering improves on the
performance of bilinear filtering by storing the image at multiple sizes (known as mip-
mapping ) and then sampling in three dimensions, combining pixels from the larger and
smaller stored image representations to create the final result.
The advantage of this approach is that the algorithm can work from a pair of images that are
already quite close to the final size. This means that it does not need to sample as many
pixels simultaneously, which improves performance and avoids the sampling glitches that
can occur at very small scale factors due to rounding errors.
Figure 4.14 For larger images, bilinear or trilinear filtering is usually better.
Search WWH ::




Custom Search