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 10. Bitmap<br />

color bitmap, but we use only monochrom colors) is created by calling function CBitmap::<br />

CreateCompatibleBitmap(…). Since the DC supports color bitmap (If the program is being run on a system<br />

with a color monitor) , this will create a color bitmap compatible with the window DC.<br />

Then we select the color bitmap and the binary bitmaps into the memory DCs and create the outline<br />

mask images:<br />

……<br />

……<br />

pBmpShadowOld=dcMono.SelectObject(&bmpShadow);<br />

dcMono.FillSolidRect(0, 0, bm.bmWidth, bm.bmHeight, RGB(255, 255, 255));<br />

dcMono.BitBlt<br />

(<br />

0, 0,<br />

bm.bmWidth-1, bm.bmHeight-1,<br />

&dcColor,<br />

1, 1,<br />

SRCCOPY<br />

) ;<br />

dcMono.BitBlt<br />

(<br />

0, 0,<br />

bm.bmWidth, bm.bmHeight,<br />

&dcColor,<br />

0, 0,<br />

MERGEPAINT<br />

);<br />

dcMono.SelectObject(pBmpShadowOld);<br />

First we fill the mask bitmap with white color. Then we copy the patterns from the original image to<br />

the mask bitmap image. When doing this copy, the first horizontal line (the upper-most line) and the first<br />

vertical line (the left-most vertical line) are eleminated from the original image (Pixels with coordinates (0,<br />

y) and (x, 0) are elemented, where x can be 0, 1, … , up to width of image -1; y can be 0, 1, …, up to height<br />

of image -1). The colors contained in the souce bitmap will be automatically converted to black and white<br />

colors when we call function CDC::BitBlt(…) because the target image is a binary bitmap. The souce<br />

image is copied to the mask bitmap at the position of (0, 0). Then the original bitmap is inverted, and<br />

merged with the mask image with bit-wise OR operation. Here flag MERGEPAINT allows the pixels in the<br />

souce image and pixels in the target image to be combined in this way. After these operations, the binary<br />

bitmap image will contain the outline that should be drawn with the shadowed color.<br />

The following portion of the function generates the highlighted outline:<br />

……<br />

pBmpHilightOld=dcMono.SelectObject(&bmpHilight);<br />

dcMono.BitBlt<br />

(<br />

0, 0,<br />

bm.bmWidth, bm.bmHeight,<br />

&dcColor,<br />

0, 0,<br />

SRCCOPY<br />

);<br />

dcMono.BitBlt<br />

(<br />

0, 0,<br />

bm.bmWidth-1, bm.bmHeight-1,<br />

&dcColor,<br />

1, 1,<br />

MERGEPAINT<br />

);<br />

dcMono.SelectObject(pBmpHilightOld);<br />

dcColor.SelectObject(pBmpOld);<br />

……<br />

pBmpOld=dcColor.SelectObject(&bmpGray);<br />

329

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

Saved successfully!

Ooh no, something went wrong!