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 />

Draw this<br />

portion with<br />

shadowed color<br />

Draw this<br />

portion with<br />

highlighted color<br />

Figure 10-3. Implement chiseled effect<br />

The highlighted outline can be obtained in the same way, but we need to combine the original bitmap<br />

and the inverted bitmap differently here:<br />

1) Draw the original bitmap at position (1, 1).<br />

1) Invert the bitmap image.<br />

1) Combine the inverted image with the original image with bit-wise OR operation, with the inverted<br />

image be put at position (0, 0) (Figure 10-5).<br />

If we combine the two outlines and paint them with highlighted and shadowed colors respectively, then<br />

fill the rest part with a normal color (A color between the highlighted and shadowed color), we will have a<br />

3D effect. For example, we can use white as the highlighted color, dark gray as the shadowed color, and<br />

light gray as the normal color.<br />

Draw original<br />

image at (0, 0)<br />

Resulted outline<br />

Combine them<br />

using bit-wise OR<br />

operation<br />

Draw inverted<br />

image at (1, 1)<br />

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

Creating Binary Bitmap Image<br />

So we need to generate monochrome black/white binary image from the original color bitmap. Of<br />

course we can examine every pixel one by one and compare its brightness with a threshold (Usually the<br />

threshold value is set to the middle between the brightest and darkest color, which are white and black<br />

respectively). If the brightness of a pixel is greater than the threshold, its color is set to white, otherwise it<br />

will be set to black.<br />

However, we can implement this conversion in an easier way. Remember, when creating the bitmap by<br />

calling function CBitmap::CreateBitmap(…), we are allowed to specify the bitmap’s attributes, which<br />

includes the dimension of the image, number of bytes in each raster line, and bit count per pixel. Here, the<br />

bit count per pixel indicates how many bits will be used for representing a single pixel. If we set it to 1, the<br />

325

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

Saved successfully!

Ooh no, something went wrong!