Adjusting Images for Different Sizes
In some circumstances, a graphic image might need to fit in a different amount of space than originally intended. For example, a user may adjust the global scaling constant using the Custom Font Size feature, or an application might allow the user to choose a differently sized font. In these cases, an application might draw an image that appears unexpectedly out of scale with the surrounding text or other window elements. Different methods of adjusting images are described in the following sections.
Alternatives to bitmaps
Adjusting images is especially a problem for bitmaps, which are not automatically scaled and do not usually look good when stretched. The best solution is to avoid using bitmaps altogether and use instead another kind of image that is designed to scale well. The following alternatives can be used in place of bitmaps:
- Metafiles are a convenient way to encapsulate an image for easy playback. They can automatically be scaled to fit the destination rectangle and normally look good at almost any size. (Of course, this benefit is lost if the metafile itself contains things that do not scale, such as bitmaps.)
- If the image is simple and you do not need to encapsulate it for easy storage and playback, you can create a routine that draws it on the fly using Windows graphic functions.
- TrueType glyphs can represent the image. This solution can be expensive if the expertise to create glyphs is not available in-house, but the image can be optimized for any size. A complex TrueType glyph will not be recognized by an accessibility aid, so you should label the graphic using the techniques described earlier in "Use of Bitmapped Text."
Accommodating bitmaps when changing size
Several methods can be used to accommodate a bitmap to differently sized regions:
- You can scale your bitmap "at run time" using the StretchBlt function so that it will be sized appropriately for its screen location.
- If you do not stretch your bitmap for an enlarged space, you can draw it at its normal size and leave blank space around it. However, to ensure that the region around your bitmap does not have unrelated, older information lying around, you should erase the region to the appropriate background color. You should specify the size of the region using a drawing method other than MM_TEXT so that it will automatically adjust to any global scaling factor.
- If you do not shrink your bitmap to fit a smaller space, you should make sure that the bitmap is properly clipped to the surrounding rectangle — for example, when the Custom Font Size feature is used to select a global scaling ratio of less than 100%. You should specify the size of the region using a drawing method other than MM_TEXT so that it will automatically adjust to any global scaling factor.