11.04.2014 Views

Advanced MFC Programming

Advanced MFC Programming

Advanced MFC Programming

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 10. Bitmap<br />

image can have only 2 colors, and will be automatically converted to mono chrome fomat no matter what<br />

kind of data we use to initialize the bitmap.<br />

Draw original<br />

image at (1, 1)<br />

Combine them<br />

using bit-wise OR<br />

operation<br />

Draw inverted<br />

image at (0, 0)<br />

Resulted outline<br />

Figure 10-5. Generate the outline that should be drawn with highlighted color<br />

Raster Operation Mode<br />

Another issue needs to be discussed here is how to draw the outline portion using specified color<br />

without affecting rest part of the image. In order to implement this, we can treat the two outline bitmaps as<br />

masks, and draw only the unmasked pixels with specified colors. This procedure is similar to that of<br />

drawing bitmaps with transparency.<br />

When calling function CDC::BitBlt(…) or CDC::StretchBlt(…) to paint the bitmap, we always need<br />

to specify the drawing mode, which specifies how to combine the pixels in the source bitmap with the<br />

corresponding destination pixels. This drawing mode is also called raster operation mode, because it is<br />

applicable only to raster devices (Contary to the raster devices are vector devices, for example, a plotter is a<br />

vector device). We have many choices such as bit-wise AND, OR, XOR etc. Actually, we can specify more<br />

complex combinations among the following three different objects when calling the above two functions:<br />

the pixel in the source bitmap, the corresponding pixel in the target device, and the brush currently being<br />

selected by the DC. We can specify up to three Boolean bit-wise operations among them.<br />

For example, the following operation will draw the outline on the destination bitmap with the brush<br />

color:<br />

(Brush Color) XOR (Destinaton Color) AND (Source Color) XOR (Brush Color)<br />

The reason is simple: After the first operation (between the brush and destination pixels), the pixels in<br />

the target device will become the XOR combination between the original pixel colors and the brush color.<br />

Next, this XORed result will be ANDed with the source bitmap (Only the outlined part is black, rest part is<br />

white), the outlined part on the target device will become black and the rest part remains unchanged (still<br />

XORed result from the first operation). Then we do XOR again between the target device and the brush, for<br />

the outlined part, this operation will fill it with the brush color (A ^ 0 = A); for the rest part, this will<br />

resume the original color for every pixel (A ^ B ^ A = B).<br />

Chiselled Effect<br />

With the following steps, we can create chiselled effect:<br />

1) Create a brush with shadowed or highlighted color.<br />

1) Paint the destination with the brush using bit-wise XOR operation mode.<br />

1) Draw the mask bitmap on the target device using bit-wise AND operation mode.<br />

326

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

Saved successfully!

Ooh no, something went wrong!