Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.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中提取点坐标(x,y)#_C#_Image Processing_Cubic Spline - Fatal编程技术网

C# 从曲线c中提取点坐标(x,y)#

C# 从曲线c中提取点坐标(x,y)#,c#,image-processing,cubic-spline,C#,Image Processing,Cubic Spline,我有一条曲线,我使用graphics.drawcurve(笔、点、张力)的方法在c#的画框上绘制 我是否可以提取曲线覆盖的所有点(x,y坐标)?然后将它们保存到数组或列表中,或者其他任何东西都很好,这样我就可以在不同的东西中使用它们 我的代码: void Curved() { Graphics gg = pictureBox1.CreateGraphics(); Pen pp = new Pen(Color.Green, 1); int i,j; Point[]

我有一条曲线,我使用graphics.drawcurve(笔、点、张力)的方法在c#的画框上绘制

我是否可以提取曲线覆盖的所有点(x,y坐标)?然后将它们保存到数组或列表中,或者其他任何东西都很好,这样我就可以在不同的东西中使用它们

我的代码:

void Curved()
{
    Graphics gg = pictureBox1.CreateGraphics();
    Pen pp = new Pen(Color.Green, 1);
    int i,j;
    Point[] pointss = new Point[counter];

    for (i = 0; i < counter; i++)
    {
        pointss[i].X = Convert.ToInt32(arrayx[i]);
        pointss[i].Y = Convert.ToInt32(arrayy[i]);
    }
    gg.DrawCurve(pp, pointss, 1.0F);
}
void曲线()
{
Graphics gg=pictureBox1.CreateGraphics();
钢笔pp=新钢笔(颜色为绿色,1);
int i,j;
点[]点SS=新点[计数器];
对于(i=0;i

非常感谢

如果你真的想要一个像素坐标列表,你仍然可以让GDI+来完成繁重的工作:

using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace so_pointsfromcurve
{
    class Program
    {
        static void Main(string[] args)
        {
            /* some test data */
            var pointss = new Point[]
            {
                new Point(5,20),
                new Point(17,63),
                new Point(2,9)
            };
            /* instead of to the picture box, draw to a path */
            using (var path = new GraphicsPath())
            {
                path.AddCurve(pointss, 1.0F);
                /* use a unit matrix to get points per pixel */
                using (var mx = new Matrix(1, 0, 0, 1, 0, 0))
                {                    
                    path.Flatten(mx, 0.1f);
                }
                /* store points in a list */
                var list_of_points = new List<PointF>(path.PathPoints);
                /* show them */
                int i = 0;
                foreach(var point in list_of_points)
                {
                    Debug.WriteLine($"Point #{ ++i }: X={ point.X }, Y={point.Y}");
                }
            }

        }
    }
}
使用System.Collections.Generic;
使用系统诊断;
使用系统图;
使用System.Drawing.Drawing2D;
命名空间so_点自曲线
{
班级计划
{
静态void Main(字符串[]参数)
{
/*一些测试数据*/
var pointss=新点[]
{
新点(5,20),
新点(17,63),
新观点(2,9)
};
/*绘制到路径,而不是图片框*/
使用(var path=new GraphicsPath())
{
路径.添加曲线(点S,1.0F);
/*使用单位矩阵获得每个像素的点*/
使用(var mx=新矩阵(1,0,0,1,0,0))
{                    
路径平坦(mx,0.1f);
}
/*在列表中存储点*/
var list of_points=新列表(path.PathPoints);
/*给他们看*/
int i=0;
foreach(变量点列表中的变量点)
{
Debug.WriteLine($“点{++i}:X={Point.X},Y={Point.Y}”);
}
}
}
}
}
这种方法将样条曲线绘制到一条路径,然后使用内置功能将该路径展平到一组足够密集的线段(大多数矢量绘图程序也是这样做的),然后将路径点从线网格提取到
点f
s列表中


GDI+设备渲染的人工制品(平滑、抗锯齿)在此过程中丢失。

如果您确实想要像素坐标列表,您仍然可以让GDI+完成繁重的工作:

using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace so_pointsfromcurve
{
    class Program
    {
        static void Main(string[] args)
        {
            /* some test data */
            var pointss = new Point[]
            {
                new Point(5,20),
                new Point(17,63),
                new Point(2,9)
            };
            /* instead of to the picture box, draw to a path */
            using (var path = new GraphicsPath())
            {
                path.AddCurve(pointss, 1.0F);
                /* use a unit matrix to get points per pixel */
                using (var mx = new Matrix(1, 0, 0, 1, 0, 0))
                {                    
                    path.Flatten(mx, 0.1f);
                }
                /* store points in a list */
                var list_of_points = new List<PointF>(path.PathPoints);
                /* show them */
                int i = 0;
                foreach(var point in list_of_points)
                {
                    Debug.WriteLine($"Point #{ ++i }: X={ point.X }, Y={point.Y}");
                }
            }

        }
    }
}
使用System.Collections.Generic;
使用系统诊断;
使用系统图;
使用System.Drawing.Drawing2D;
命名空间so_点自曲线
{
班级计划
{
静态void Main(字符串[]参数)
{
/*一些测试数据*/
var pointss=新点[]
{
新点(5,20),
新点(17,63),
新观点(2,9)
};
/*绘制到路径,而不是图片框*/
使用(var path=new GraphicsPath())
{
路径.添加曲线(点S,1.0F);
/*使用单位矩阵获得每个像素的点*/
使用(var mx=新矩阵(1,0,0,1,0,0))
{                    
路径平坦(mx,0.1f);
}
/*在列表中存储点*/
var list of_points=新列表(path.PathPoints);
/*给他们看*/
int i=0;
foreach(变量点列表中的变量点)
{
Debug.WriteLine($“点{++i}:X={Point.X},Y={Point.Y}”);
}
}
}
}
}
这种方法将样条曲线绘制到一条路径,然后使用内置功能将该路径展平到一组足够密集的线段(大多数矢量绘图程序也是这样做的),然后将路径点从线网格提取到
点f
s列表中


GDI+设备渲染的人工制品(平滑、抗锯齿)在此过程中丢失。

您绘制它-只需将传递到某些
列表中
绘制曲线的点保存下来即可。当然,用于绘图的数据可以存储和重用。图纸所涵盖的所有点都不容易收集。通过将曲线添加到graphicspath,然后展平路径,可以得出近似值。结果是近似直线的点;一切都应该在曲线上。也许是摩尔邻居算法?我发现该方法基于三次样条插值,我更新了我的问题并添加了代码。如果曲线是函数的图形,则应始终直接从该函数进行渲染,以便结果适应目标设备的分辨率<代码>绘制曲线
,从数学上讲,会生成一条曲线。当您逐像素对其进行采样时,您将受限于该尺寸和分辨率,并失去图形子系统所做的平滑和抗锯齿。您绘制它-只需将传递到某些
列表中的
绘制曲线中的点保存下来即可。当然,用于绘图的数据可以存储和重用。图纸所涵盖的所有点都不容易收集。通过将曲线添加到graphicspath,然后展平路径,可以得出近似值。结果是近似直线的点;一切都应该在曲线上。也许是摩尔邻居算法?我发现该方法基于三次样条插值,我更新了我的问题并添加了代码。如果曲线是函数的图形,则应始终直接从该函数进行渲染,以便结果适应目标设备的分辨率<代码>绘制曲线
,从数学上讲,会生成一条曲线。当逐像素对其采样时,您将受限于该尺寸和分辨率,并失去图形所做的平滑和抗锯齿