Tag: graphicspath

编辑FreeShape的点

我有一些GUI让用户绘制costimized GraphicsPath。 我使用GraphicsPath AddLine函数创建了它。 现在,我想实现您在附加的Microsoft Word图像中看到的内容 – “编辑点”。 我面临几个问题: 我的路径有“线条” – >每个只有一个像素大小。 我只想选择“关键点”。 我怎么做? 这是“Flatten”的逆转,找不到这样的function。 是否存在.Net函数来绘制小的蓝色矩形,以及路径周围的小绿圈? 以及每个选定点周围的矩形怎么样? 每个帮助,甚至部分,将不胜感激。

Region.IsVisible(PointF)对于大浮点值的性能非常慢

我遇到了一个奇怪的性能问题,对我正在经历的行为进行解释会很棒。 我正在使用System.Drawing.Region.IsVisible(PointF)来确定一个点是否在多边形内。 这通常效果很好,但昨天我注意到,如果多边形很复杂并且由大的x和y值组成,则IsVisible方法的性能会变得非常慢。 下面是一些重现问题的代码(以及显示多边形形状的图像),对于较大的数组大小而言,遗憾的是,在问题出现之前,多边形需要非常复杂。 当在原始点上调用IsVisible时,我的机器需要460 651毫秒才能完成,而当我首先将所有点除以1000,然后调用该方法时,它需要1毫秒。 为什么我在时间上看到如此大的差异? 我不认为浮动的实际值会影响性能。 using System; using System.Diagnostics; using System.Drawing; using System.Drawing.Drawing2D; using System.Linq; namespace PerformanceTest { class Program { static void Main(string[] args) { // Create complex polygon with large x and y values float[] xValues = {1.014498E+07f, 1.016254E+07f, 1.019764E+07f, 1.021519E+07f, 1.023274E+07f, 1.026785E+07f, 1.026785E+07f, 1.02854E+07f, 1.02854E+07f, 1.030295E+07f, 1.03205E+07f, 1.033805E+07f, 1.035561E+07f, […]

奇怪地使用Graphics.FillPath绘制GraphicsPath

我编写了一些代码,它创建了一个圆角矩形GraphicsPath ,基于自定义结构BorderRadius (允许我定义矩形的左上角,右上角,左下角和右下角),以及初始的Rectangle本身: public static GraphicsPath CreateRoundRectanglePath(BorderRadius radius, Rectangle rectangle) { GraphicsPath result = new GraphicsPath(); if (radius.TopLeft > 0) { result.AddArc(rectangle.X, rectangle.Y, radius.TopLeft, radius.TopLeft, 180, 90); } else { result.AddLine(new System.Drawing.Point(rectangle.X, rectangle.Y), new System.Drawing.Point(rectangle.X, rectangle.Y)); } if (radius.TopRight > 0) { result.AddArc(rectangle.X + rectangle.Width – radius.TopRight, rectangle.Y, radius.TopRight, radius.TopRight, 270, 90); } else { […]

从半透明位图创建GraphicsPath

我想创建一个GraphicsPath和一个Points列表,以形成位图的非透明区域的轮廓。 如果需要,我可以保证每个图像只有一个非透明像素的固体集合。 因此,例如,我应该能够沿着像素的边缘顺时针或逆时针记录点并执行完全闭环。 这种算法的速度并不重要。 但是,如果我可以在较小且不太复杂的GraphicsPath中跳过某些点来减少,那么结果点的效率是非常重要的。 我将列出下面的当前代码,该代码与大多数图像完美配合。 但是,一些更复杂的图像最终会出现以错误顺序连接的路径。 我想我知道为什么会这样,但我无法想出解决方案。 public static Point[] GetOutlinePoints(Bitmap image) { List outlinePoints = new List(); BitmapData bitmapData = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); byte[] originalBytes = new byte[image.Width * image.Height * 4]; Marshal.Copy(bitmapData.Scan0, originalBytes, 0, originalBytes.Length); for (int x = 0; x < bitmapData.Width; x++) { for (int y […]