1

I am trying to draw the intersection of one blue rectangle and one yellow rectangle

 ,-------------------,
 |                   |
 |     Blue          |
 |           ,-------+---------,
 |           | Green |         |
 '-----------+-------, Yellow  |
             |_________________|

using the methods CDC::Polygon and CDC::SetBkMode(TRANSPARENT)

but all I get is this :

 ,-------------------,
 |                   |
 |     Blue          |
 |           ,-------+---------,
 |           |                 |
 '-----------+      Yellow     |
             |_________________|

Please give me a simple solution sticking with the MFC.

Thanks.

4

1 に答える 1

3

You cannot do this, regardless of whether SetBkMode is TRANSPARENT or OPAQUE since Polygon uses the currently selected brush to fill the polygon's interior. Instead what you should do is this:

Paint one rectangle first, paint the other rectangle next and then calculate the intersection of the two rectangles using CRect::IntersectRect (see http://msdn.microsoft.com/en-us/library/262w7389(v=vs.100).aspx).

If the intersection is non-empty, calculate the resulting "color blend" and create the appropriate brush and, using it, draw a third rectangle using.

For more information on how to blend the colors, check out Algorithm for Additive Color Mixing for RGB Values right here on StackOverflow.

于 2012-11-13T15:37:50.693 に答える