It is necessary to take n points of type Point “draw” a closed filled polygon. And if a certain point on the "canvas" is drawn, then the corresponding element of the array bool[,] becomes true .

I give the code, which, I think, should perform this task. But of course it only seems to me and as a result I get an empty “canvas”.

 //точки масива List<Point> ps = new List<Point>(); ps.Add(new Point(10, 0)); ps.Add(new Point(0, 0)); ps.Add(new Point(0, 10)); //не понял для чего GraphicsPath требует byte [] types List<byte> ppt = new List<byte>(); ppt.Add(0); ppt.Add(0); ppt.Add(0); //System.Drawing.Drawing2D.GraphicsPath GraphicsPath gp = new GraphicsPath(ps.ToArray(), ppt.ToArray()); //попытка замкнуть контур gp.Flatten(); //переменная, ради которой было произведено все вышенаписанное bool[,] bmp = new bool[11, 11]; for (int x = 0; x < 11; x++) for (int y = 0; y < 11; y++) if (gp.IsVisible((float)x, (float)y)) bmp[x, y] = true; else bmp[x, y] = false; //следующий код только для визуализации Bitmap visual = new Bitmap(11, 11); for (int x = 0; x < 11; x++) for (int y = 0; y < 11; y++) if (bmp[x, y]) visual.SetPixel(x, y, Color.Red); visual.Save("bmp.png"); 

Thought to do so . But it seems to me that in C # this bike was invented a long time ago.

You can, of course, and so draw a polygon

 Graphics g = Graphics.FromImage(img); Point[] points=...; g.DrawPolygon(blackPen, points); 

But something tells me that working with Image img = new Bitmap(x,y) load the comp more strongly than bool [,] img = new bool [x,y]

    1 answer 1

    Found the answer in MSDN why drawing does not work for me.

    The initialization string below does not create a polygon in gp

     GraphicsPath gp = new GraphicsPath(ps.ToArray(), ppt.ToArray()); 

    Instead, you need to do this:

     GraphicsPath gp = new GraphicsPath(); //ВОТ так надо добавлять точки, чтобы получить полигон gp.AddLines(ps.ToArray()); 

    And here is the full code that already works:

     //точки масива List<Point> ps = new List<Point>(); ps.Add(new Point(10, 0)); ps.Add(new Point(0, 0)); ps.Add(new Point(0, 10)); ps.Add(new Point(3, 1)); GraphicsPath gp = new GraphicsPath(); gp.AddLines(ps.ToArray()); //перемення, ради которой было произведено все вышенаписанное bool[,] bmp = new bool[11, 11]; for (int x = 0; x < 11; x++) for (int y = 0; y < 11; y++) if (gp.IsVisible((float)x, (float)y)) bmp[x, y] = true; else bmp[x, y] = false; //следующий код только для визуализации Bitmap visual = new Bitmap(11, 11); for (int x = 0; x < 11; x++) for (int y = 0; y < 11; y++) if (bmp[x, y]) visual.SetPixel(x, y, Color.Red); visual.Save("bmp.png"); 
    • so why doesn't it work? - Grundy
    • because I did so GraphicsPath gp = new GraphicsPath (ps.ToArray (), ppt.ToArray ()); and found what to do with gp.AddLines (ps.ToArray ()); - Ilya
    • Add this description in the answer, otherwise it is not clear what exactly has changed - Grundy
    • @Grundy: Because the wrong PathPointType was specified, apparently. - VladD