Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Chapter 8 GDI Orientation and Transformations Visual C++ and MFC Fundamentals


7.1 Colors.............................................................................................................


7.1.1 Overview


The color is one the most fundamental objects that enhances the aesthetic appearance of
an object. The color is a non-spatial object that is added to an object to modify some of
its visual aspects. The MFC library, combined with the Win32 API, provides various
actions you can use to take advantage of the various aspects of colors.

Three numeric values are used to create a color. Each one of these values is 8 bits. The
first number is called red. The second is called green. The third is called blue:

Bits
Red 7 6 5 4 3 2 1 0

Green 7 6 5 4 3 2 1 0

Blue 7 6 5 4 3 2 1 0

Converted to decimal, each one of these numbers would produce:

27 + 2^6 + 2^5 + 2^4 + 2^3 + 2^2 + 2^1 + 2^0

= 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1

= 255

Therefore, each number can have a value that ranges from 0 to 255 in the decimal system.
These three numbers are combined to produce a single number as follows:

Color
Value

23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Blue Green Red

Converted to decimal, this number has a value of 255 * 255 * 255 = 16581375. This
means that we can have approximately 16 million colors available. The question that
comes to mind is how we use these colors, to produce what effect.

You computer monitor has a surface that resembles a series of tinny horizontal and
vertical lines. The intersection of a one horizontal line and a vertical line is called a pixel.
This pixel holds, carries, or displays one color.
Free download pdf