Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 多边形C上的Bresenhams_C#_Bresenham - Fatal编程技术网

C# 多边形C上的Bresenhams

C# 多边形C上的Bresenhams,c#,bresenham,C#,Bresenham,我需要从闭合的2d多边形中像素化/获取点。不是轮廓,而是用像素填充,体素以点的形式检索它们的位置。 现在我已经有了线光栅化的C代码,有没有类似于多边形的方法?只需使用绘制线绘制多边形即可。绘制多边形没有特定的算法 void DrawPoly(IEnumerable<Point> points) { endpoints = points.Skip(1).Concat(new []{points.First()}); pairs = points.Zip(endpoint

我需要从闭合的2d多边形中像素化/获取点。不是轮廓,而是用像素填充,体素以点的形式检索它们的位置。
现在我已经有了线光栅化的C代码,有没有类似于多边形的方法?

只需使用绘制线绘制多边形即可。绘制多边形没有特定的算法

void DrawPoly(IEnumerable<Point> points)
{
    endpoints = points.Skip(1).Concat(new []{points.First()});
    pairs = points.Zip(endpoints, Tuple.Create);

    for(var pair in pairs)
    {
        DrawLine(pair.Item1, pair.Item2);
    }
}

void DrawLine(Point p1, Point p2)
{
    // Your Bresenham code here
}

我怎样才能把矩阵和存储的填充像素连接起来

public static List<Tuple<int, int>> PixelizePolygon(PaintEventArgs e)
{
    List<Tuple<int,int>> pixels = new List<Tuple<int, int>>();

    // Create solid brush.
    SolidBrush blueBrush = new SolidBrush(Color.Blue);

    // Create points that define polygon.
    PointF point1 = new PointF(50.0F, 50.0F);
    PointF point2 = new PointF(100.0F, 25.0F);
    PointF point3 = new PointF(200.0F, 5.0F);
    PointF point4 = new PointF(250.0F, 50.0F);
    PointF point5 = new PointF(300.0F, 100.0F);
    PointF point6 = new PointF(350.0F, 200.0F);
    PointF point7 = new PointF(250.0F, 250.0F);
    PointF[] curvePoints = { point1, point2, point3, point4, point5, point6, point7 };

    // Define fill mode.
    FillMode newFillMode = FillMode.Winding;

    // Fill polygon to screen.
    e.Graphics.FillPolygon(blueBrush, curvePoints, newFillMode);



    return pixels;

} 

也许我的问题不准确,我正在搜索如何用像素填充多边形并检索它们的位置。像体素化。听起来你在找一个。这里列出了一些。如果要提取所有点的列表,可以选择:1。绘制时存储点,或2。将坐标附加到图像矩阵,将其展平为1D列表,然后执行.Wherep=>p.PixelValue==0。如果我有一个简单的函数来绘制多边形并填充它,如何附加图像矩阵?下面是我的第二个要点。您需要指定宽度、高度和图像。因为看起来您使用的是RGB图像,所以最后一行变为filledPoints=flatten。其中p=>p.PixelValue.Blue==0。Selectp=>p.Coordinate;。等等,我有问题,因为我真的不想使用windows窗体进行此操作,只需提取有关点的信息。有没有其他方法可以使用此函数将多边形填充到屏幕。e、 Graphics.FillPolygonblueBrush、curvePoints、newFillMode;或者,我应该如何从此行继续或检索有关屏幕的信息?
public static List<Tuple<int, int>> PixelizePolygon(PaintEventArgs e)
{
    List<Tuple<int,int>> pixels = new List<Tuple<int, int>>();

    // Create solid brush.
    SolidBrush blueBrush = new SolidBrush(Color.Blue);

    // Create points that define polygon.
    PointF point1 = new PointF(50.0F, 50.0F);
    PointF point2 = new PointF(100.0F, 25.0F);
    PointF point3 = new PointF(200.0F, 5.0F);
    PointF point4 = new PointF(250.0F, 50.0F);
    PointF point5 = new PointF(300.0F, 100.0F);
    PointF point6 = new PointF(350.0F, 200.0F);
    PointF point7 = new PointF(250.0F, 250.0F);
    PointF[] curvePoints = { point1, point2, point3, point4, point5, point6, point7 };

    // Define fill mode.
    FillMode newFillMode = FillMode.Winding;

    // Fill polygon to screen.
    e.Graphics.FillPolygon(blueBrush, curvePoints, newFillMode);



    return pixels;

}