绘制边境仅内部图像的非透明部分 [英] Draw border just inside non-transparent portion of image

查看:141
本文介绍了绘制边境仅内部图像的非透明部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个线程几乎是我所需要的: <一href="http://stackoverflow.com/questions/9752410/creating-a-graphicspath-from-a-semi-transparent-bitmap">Creating从半透明的位图一个GraphicsPath的

this thread is almost what I need: Creating a GraphicsPath from a semi-transparent bitmap

但他周围绘制图像的轮廓 - 我需要抓一张只是一对夫妇里面的图像像素。基本上我想要画一个焦点矩形(除非它不是一个矩形) 结果需要在一个GraphicsPath的形式,所以我能适应它的权利到我目前的code。

but he is drawing an outline AROUND the image - I need to draw one just a couple of pixels INSIDE the image. basically I'm trying to draw a "Focus Rectangle" (except it's not a rectangle) the result needs to be in the form of a GraphicsPath so i can fit it right into my current code.

私有函数GetImagePath(IMG的图像)作为的GraphicsPath ... 端功能

private function GetImagePath(img as Image) as GraphicsPath ... end function

好吧,首先,我不能甚至可以从其他职位的code工作。我不断收到指数超出范围,在该行:

ok, first of all i cant even get the code from the other post to work. i keep getting index out of range at this line:

*字节的α= originalBytes [Y * bitmapData.Stride + 4 * X + 3]; *

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

这是如果它甚至会过去其他的东西第一。次数很多它出来的第一环路的具有未发现非透明点 - 当大部分的图像是不透明的

that's IF it even gets past the other stuff first. alot of times it comes out of the first loop having not found a non-transparent point - when most of the image is non-transparent.

的newst问题是,它创建点不作任何意义的列表。图像68x68我点的名单有一个像290x21点,甚至疯狂的像2316x-15

the newst problem is that it creates a list of point that dont make any sense. the image is 68x68 my list of points has points like 290x21 and even crazier ones like 2316x-15

这是我原来的形象:

[不会让我上载的原因即时通讯新]

[wont let me upload cause im new]

按钮的背景图像是70x70 - 如果,在所有重要的

its the background image of a button that is 70x70 - if that matters at all.

推荐答案

我会觉得使用中的链接提供的程序,得到它的输出,并添加您自己的包装围绕它修改推在情侣路像素你想要的。你甚至可以使像素的数量在输入参数移动,让您可以玩它。

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.

否则,你可以直接添加二传进提供的程序。无论哪种方式,我认为这是一个2回合方法。你需要找对象的外部边界,也就是提供什么。然后,你需要基本上围绕路径移动自己,了解道路的导数,这样你可以移动路径垂直于衍生于你正在寻找在当前点。您还必须从外部内部识别(即哪个方向移动线)。

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:

这篇关于绘制边境仅内部图像的非透明部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆