1

这个线程几乎是我需要的: Creating a GraphicsPath from a semi-transparent bitmap

但他正在图像周围绘制轮廓 - 我需要在图像内部绘制一个仅几个像素的轮廓。基本上我正在尝试绘制一个“焦点矩形”(除非它不是矩形),结果需要采用 GraphicsPath 的形式,以便我可以将它直接放入我当前的代码中。

私有函数 GetImagePath(img as Image) as GraphicsPath ...结束函数

[编辑] 好的,首先我什至无法从其他帖子中获取代码来工作。我一直在这一行得到索引超出范围:

*byte alpha = originalBytes[y * bitmapData.Stride + 4 * x + 3];*

那就是如果它甚至先通过其他东西。很多时候它从第一个循环中出来并没有找到一个不透明的点——当大部分图像是不透明的时候。

最新的问题是它创建了一个没有任何意义的点列表。图像是 68x68 我的点列表有像 290x21 这样的点,甚至像 2316x-15 这样更疯狂的点

这是我的原始图像:

[不会让我上传因为我是新人]

它是 70x70 的按钮的背景图像 - 如果这很重要的话。

4

1 回答 1

1

我会考虑使用链接中提供的例程,从中获取输出,并在其周围添加您自己的包装器,以修改将其推入您想要的几个像素的路径。您甚至可以在输入参数中设置要移动的像素数量,以便您可以使用它。

否则,您可以将第二遍直接添加到提供的例程中。无论哪种方式,我认为这是一种 2 遍方法。您需要找到对象的外部边界,即提供的内容。然后,您需要自己绕着路径移动,了解路径的导数,以便您可以将路径垂直于您正在查看的当前点的导数移动。您还必须从外部识别内部(即移动线的方向)。

算法可能看起来像这样(记住只是算法):

Create New List of Points for the new line

For all points i in 0 to (n-2) (points in original point list)
    // Get a New point in between
    float xNew = (x(i) + x(i + 1) ) / 2
    float yNew = (y(i) + y(i + 1) ) / 2

    // Need to figure out how much to move in X and in Y for each (pixel) move along
    // the perpendicular slope line, remember a^2 + b^2 = c^2, we have a and b
    float a = y(i + 1) - y(i)
    float b = x(i + 1) - x(i)
    float c = sqrt( (a * a) + (b * b) )

    // c being the hypotenus is always larger than a and b.
    // Lets Unitize the a and b elements
    a = a / c
    b = b / c

    // Assume the original point array is given in clockwise fashion
    a = -a
    b = -b

    // Even though a was calculated for diff of y, and b was calculated for diff of x
    // the new x is calculated using a and new y with b as this is what gives us the
    // perpendicular slope versus the slope of the given line
    xNew = xNew + a * amountPixelsToMoveLine
    yNew = yNew + b * amountPixelsToMoveLine

    // Integerize the point
    int xListAdd = (int)xNew
    int yListAdd = (int)yNew

    // Add the new point to the list
    AddPointToNewPointList(xListAdd, yListAdd)

Delete the old point list

我正在执行的几何图形的图像: 我在上面通过算法描述的几何图形

于 2012-05-30T17:04:25.053 回答