Click to See Complete Forum and Search --> : XOR drawing shape algorithms?


guoyanpeng
November 29th, 2005, 09:12 PM
I have such a requirement. Draw a complex shape, for instance, a 5-points star within a rectangle area. And I need to get the rest area of this 5-points star (need to use a polygon objects to represent it, maybe?)
In another words, give the backgroud rectangle, and the shape, need a XOR algorithm to get the rest area.
Is there anybody can briefly introduce such an algorithm? Or where can I get it? Or please tell me the name or pattern of this algorithm, so that I can search it.

olivthill
November 30th, 2005, 03:57 AM
If I undersand well the question, you want the bitmap of a star with white pixels inside, and black pixels outside, otherwise said a mask of a star. This is more related to geometry and coloring techniques than to XOR operations.

Graphical operations heavily depend on the graphic library you want to use. If you are using Windows and GDI APIs (standard graphical APIs), then you can do the following:

1. Paint an area in black:
1.1. Select a black pen.
1.2. Select a black brush.
1.3. Use the Rectangle() API to draw a black square or rectangle.

2. Paint a white star:
2.1. Define a set of points.
2.2. Select a white pen.
2.3. Select a white brush.
2.4. Draw your star with the Polygon() API.

3. Save the bitmap:
3.1. Fill a BitmapInfo structure.
3.2. Allocate memory for DIBits.
3.3. Call GetDIBits() to get the pixels of the star.
3.4. Call CreatDIBitmap() to create a bitmap.

4. When you want to use your star:
4.1. Call SelectObject() to select the mask of the star in a DC.
4.2. Call BitBlt() to copy the mask at the desired place.

5. When you no longer need the bitmap of your star:
5.1. Call DeleteObject() to delete the bitmap.
5.2. Free the memory for the pixels of the bitmap.