locked
Filling an irregular shape RRS feed

  • Question

  • Hello,

    I am writing a paint application for Windows Mobile 5.0.

    I need to fill an irregular shape with a particular color. I have found ways on the internet, but they are not for the .Net Compact Framework.

    Can anyone please tell me how to do it in a SmartDevice project?

    Thanks.
    Thursday, September 18, 2008 6:10 PM

Answers

  • Hy

    Maybe this helps:

     

    Graphics..::.FillPolygon Method (Brush, array<Point>[]()[])

    Fills the interior of a polygon defined by an array of points specified by Point structures.

    http://msdn.microsoft.com/en-us/library/0df9swbe.aspx

     

    .NET Compact Framework

    Supported in: 3.5, 2.0, 1.0

    public void FillPolygonPoint(PaintEventArgs e)
    {
    
        // Create solid brush.
        SolidBrush blueBrush = new SolidBrush(Color.Blue);
    
        // Create points that define polygon.
        Point point1 = new Point(50, 50);
        Point point2 = new Point(100, 25);
        Point point3 = new Point(200, 5);
        Point point4 = new Point(250, 50);
        Point point5 = new Point(300, 100);
        Point point6 = new Point(350, 200);
        Point point7 = new Point(250, 250);
        Point[] curvePoints = {point1, point2, point3, point4, point5, point6, point7};
    
        // Draw polygon to screen.
        e.Graphics.FillPolygon(blueBrush, curvePoints);
    }
    
    Daniel
     
    Thursday, September 18, 2008 8:20 PM
  • What's the problem you are facing when porting the desktop code to mobile devices? For those classes/methods that are not included in .NET CF, you might have to P/Invoke native GDI functions.

     

    Monday, September 22, 2008 5:01 AM

All replies

  • Hy

    Maybe this helps:

     

    Graphics..::.FillPolygon Method (Brush, array<Point>[]()[])

    Fills the interior of a polygon defined by an array of points specified by Point structures.

    http://msdn.microsoft.com/en-us/library/0df9swbe.aspx

     

    .NET Compact Framework

    Supported in: 3.5, 2.0, 1.0

    public void FillPolygonPoint(PaintEventArgs e)
    {
    
        // Create solid brush.
        SolidBrush blueBrush = new SolidBrush(Color.Blue);
    
        // Create points that define polygon.
        Point point1 = new Point(50, 50);
        Point point2 = new Point(100, 25);
        Point point3 = new Point(200, 5);
        Point point4 = new Point(250, 50);
        Point point5 = new Point(300, 100);
        Point point6 = new Point(350, 200);
        Point point7 = new Point(250, 250);
        Point[] curvePoints = {point1, point2, point3, point4, point5, point6, point7};
    
        // Draw polygon to screen.
        e.Graphics.FillPolygon(blueBrush, curvePoints);
    }
    
    Daniel
     
    Thursday, September 18, 2008 8:20 PM
  • Hi LOBOMINATOR

    You are exactly rite way.because of 
    you can build point array, then pass to
     
    e.Graphics.DrawPolygon(Pen, Points);

    it's draw outer line  for the
    Polygon.


    thank you
    Friday, September 19, 2008 1:25 AM
  • Hi

    I will not be knowing the shape I am going to fill. Its a raster paint application. The user will draw some arbitrary closed polygon with a pencil tool and may attempt to fill it.

    I have used the 4-way flood fill algorithms to fill it out myself pixel by pixel, but its too slow. It taking 5 - 10 seconds to fill the bigger polygons. I'd really appreciate it if someone could tell me how to implement a better algorithm that fills in a practical amount of time (or almost instantly ), or if some function is available to do so.

    Thanks..
    Friday, September 19, 2008 2:04 AM
  • Hy
    But every time the user clicks on the screen you get new point coordinates which you can collect in a structure (like array of points) and if you have enough point information you can use Graphics.FillPolygon()...

    Or am I missunderstanding you?

    Daniel
    Friday, September 19, 2008 11:15 AM
  • You misunderstood me. There are various tools with which the user can draw stuff. After drawing many things, there might be several closed regions with different colors as 'boundaries'. I want to be able to fill those regions when the user uses the 'fill' tool and clicks somewhere.
    Friday, September 19, 2008 1:34 PM
  • What's the problem you are facing when porting the desktop code to mobile devices? For those classes/methods that are not included in .NET CF, you might have to P/Invoke native GDI functions.

     

    Monday, September 22, 2008 5:01 AM