C# WindowsForms PictureBox:图像中控件坐标和像素位置之间的转换 [英] C# WindowsForms PictureBox: Transformation between control coordinates and pixel position in image

查看:126
本文介绍了C# WindowsForms PictureBox:图像中控件坐标和像素位置之间的转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有图片框的控件.PictureBox 显示图像(在缩放模式下,至少在这种特殊情况下).我需要做两种事情:

I have a control with a PictureBox within it. The PictureBox displays an image (in Zoom mode, at least in this particular case). I need to do two kinds of things:

  • 点击鼠标,找出我击中图像的哪个像素
  • 在图片中给定列的图片框上画一条垂直线.

显然,我需要在控件坐标和图像中像素的(行、列)之间进行某种坐标转换.我可能找到的第一个(www.codeproject.com/Articles/20923/Mouse-Position-over-Image-in-a-PictureBox),但反之亦然.有什么想法吗?

Obviously, I need some kind of coordinate transformations between the control coordinates and the (row, column) of the pixel in the image. The first one I may have found (www.codeproject.com/Articles/20923/Mouse-Position-over-Image-in-a-PictureBox), but not the vice versa. Any ideas?

推荐答案

我可以建议一个解决方法":您不要在 PictureBox 上绘制线条等,而是在位图本身上使用它的 Graphics.那么你就可以只使用图像坐标(行、列),不需要从控件转换为图像.另一种方式(从鼠标单击到行和列),正如您所提到的,已解决并可使用.

I can suggest a "workaround": you do not draw lines etc. on the PictureBox, but, instead, on the bitmap itself, using its Graphics. Then you can only use the image coordinates (row, column) and do not need to convert from control to image. The other way round (from mouse click to row and column), as you mention, is solved and can be used.

这篇关于C# WindowsForms PictureBox:图像中控件坐标和像素位置之间的转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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