11.04.2014 Views

Advanced MFC Programming

Advanced MFC Programming

Advanced MFC Programming

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 8. DC, Pen, Brush and Palette<br />

User can avoid color approximation by increasing the color depth of the system. One simple way to do<br />

so is to reduce the screen resolution (e.g. from 1024×768 to 800×600): after the total number of pixels is<br />

reduced, the number of colors supported by the system will probably increase.<br />

As a programmer, we need to prepare for the worst situation and make our application least susceptible<br />

to the system setting. To achieve this, we need to implement local palette.<br />

Figure 8-5 Dithering effect<br />

Figure 8-6. Use nearest color for color approximation<br />

8.8 Logical Palette<br />

Palette<br />

Palette is another type of GDI objects, it encapsulates a color palette that can be used to store custom<br />

colors in an application. Although programmer can use logical palette like using an actual palette, it is not a<br />

real palette. Within any system, there is only one existing palette, which is the physical palette (or system<br />

palette). This is why the palettes created in the applications are called logical palettes. The advantage of<br />

using a logical palette is that the colors defined in the logical palette can be mapped to the system palette in<br />

an efficient way so that least color distortion can be achieved. There is no guarantee that all the colors<br />

implemented in the logical palette will be displayed without color distortion. Actually, the ultimate color<br />

realizing ability depends on the hardware. For example, if our hardware support only 256 colors and we<br />

implement a 512 logical palette, some colors defined in the logical palette will inevitably be distorted if we<br />

display all the 512 colors on the screen at the same time.<br />

223

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!