Link to home
Start Free TrialLog in
Avatar of tedunni
tedunni

asked on

Fill the area outside a Polygon (opposite of Graphics.FillPolygon)

The code snippet below will draw a polygon and then fill the area inside of that polygon.  I would like to draw a polygon (an array of points) and fill the area OUTSIDE of that polygon with a color - basically blank the area outside of a polygon with a color

Thanks
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As _
      System.Windows.Forms.PaintEventArgs) Handles _
      MyBase.Paint
    Dim polypoints() As Point
 
    ' Draw a polygon.
    polypoints = New Point() { _
        New Point(20, 110), _
        New Point(90, 150), _
        New Point(90, 100), _
        New Point(20, 150) _
    }
    e.Graphics.FillPolygon(Brushes.Red, polypoints)
    e.Graphics.DrawPolygon(Pens.Green, polypoints)
  End Sub

Open in new window

Avatar of jjardine
jjardine
Flag of United States of America image

Could you not just draw a box or rectangle over the entire screen and fill it with your color, then draw the polygon and fill it as white?
Avatar of tedunni
tedunni

ASKER

What I receive first is a bitmap image with colors and shapes already on it.  I also receive the polygon as an input.  I then take that bitmap and then draw a polygon on it.  At that point I want to color the area outside of the polygon.  

I don't believe I can do what you are suggesting jjardine because I would lose the image data that is inside the polygon.
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tedunni

ASKER

Thanks, another perfect solution.