Draw border just inside non-transparent portion of image

倖福魔咒の 提交于 2019-12-04 19:36:46

I would think to use the routine provided in the link, get the output from it, and add your own wrapper around it modifying the path pushing it in the couple pixels you want. You could even make the amount of pixels to move in an input parameter so that you can play around with it.

Else you could add the second pass directly into the routine provided. Either way I think this is a 2 pass approach. You need to find the outer bounds of the object, that is what is provided. Then you need to essentially move around the path yourself, understand the derivative of the path so that you can move your path in perpendicularly to the derivative at the current point you are looking at. You will also have to recognize inside from outside (i.e. which direction to move the line).

An Algorithm might look something like this (remember just algorithm):

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

Image of the geometry I am performing:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!