• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 634
  • Last Modified:

Drawing Complex Polygons

Hi,

I have an application on Pocket PC running Microsoft Mobile 2003, developed using Embedded Visual C++ 3.0.

I need to draw a few complex polygons (Polygons with 'holes' in them) over a black and white bitmap on a device context.

In normal windows I would use FillRegion() after CreatePolyPolygonRegion(), or set the Polygon fill mode using SetPolyFillMode().

Unfortunately both these methods are unavailable in Windows CE.

Can anyone suggest a simple alternative?

Thanks in advance,

AT.
0
Attack_Trax
Asked:
Attack_Trax
1 Solution
 
nthnhungCommented:
You can do it manually as following:
- Create a buffer whose width and height are equal or more than the polygon
- Fill the buffer with  the following recursion
CRect rect(buffer.width, buffer.height)
For(int mY=rect.top;mY<rect.bottom,++mY)
  For (int mX=rect.left;mX<rect.right;++mX)
  {
    CPoint point(mX,mY);
    if (point is Inside the polygon)
    {
          Fill this point with the correspoding pixel of bitmap
    }
    else
    {
         Fill it with some color different from black and white (e.g red)
     }
  }
Once you finished preparing buffer, you just need to draw it on the device context.
 For (int mX=rect.left;mX<rect.right;++mX)
  {
    CPoint point(mX,mY);
    if (pixel is red)
    {
           do nothing
    }
    else // pixel color is the same as bitmap color
    {
          draw on Device context
     }
  }

With this method, you can draw as many polygons as you like. You just need to compute the buffer once after user changed polygon's size.
Hope it useful!
Regards.


 
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now