通过边界坐标获取像素坐标
我正在开发一个项目,我需要找到所选区域的像素坐标。我只需单击 C# 图片框即可获得此坐标。我需要找到如图所示的灰色区域的像素坐标,以便更改该灰区域的颜色。 C# 中有定义的方法可以做到这一点吗?或者请了解如何存档此内容。
代码示例将不胜感激。
提前致谢。
选定坐标
所需区域
I'm working on a project i need to find coordinates of pixels of selected area. I'm gaining this coordinates by simply clicking on a C# picture box. I need to find the pixel coordinates of the gray area as show in the picture in order to change the color of this ash area. is there a defined method in C# do do this? or please on how to archive this.
code samples will appreciated.
thanks in advance.
Selected Coordinates
Required Area
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要的是多边形内的点算法( http://en.wikipedia.org/wiki/Point_in_polygon )
(来自 http://www.gamedev.net/topic/533455-point-in-polygon-c-implementation/ )
您也可以使用 .Net HitTestCore 方法(如果您使用)
System.Windows.Shapes.Polygon
来表示您的多边形。但我不知道这有多容易。What you need is a point-in-polygon algorithm ( http://en.wikipedia.org/wiki/Point_in_polygon )
(from http://www.gamedev.net/topic/533455-point-in-polygon-c-implementation/ )
You may also use the .Net HitTestCore Method if you use
System.Windows.Shapes.Polygon
to represent your polygon. I can't tell how easy that will work though.使用 Click 事件,并从事件中提取鼠标坐标。如果灰色区域是由函数定义的,您可以编写一个方法来检查它是否在指定的区域内。如果不是(这只是一个静态图像),您应该使用鼠标坐标来计算您单击了哪个像素,并检查其颜色值。可能有一种方法可以获取鼠标点击处的颜色值(但是,我可能会将该方法与OpenGL中的glReadPixel方法混淆)。
Use the Click event, and pull out the mouse coordinates from the event. If the gray area is defined by a function, you can write a method to check if it's within the area specified. If not (it's just a static image), you should use the mouse coordinates to calculate which pixel you have clicked, and check its color value. There might be a method to get the color value where the mouse clicks (however, I might be confusing the method with the glReadPixel method in OpenGL).