图片中点的x和y坐标 [英] x and y coordinates of a point in a picture

查看:233
本文介绍了图片中点的x和y坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 我通过鼠标移动事件在图片框中获得图像中某点的x和y坐标,但是当我用它们画一条线时,该线在另一个点上绘制.为什么?

Hi I get x and y coordinates of a point in an image in a picturebox by mouse move event but when I draw a line with them the line is drawn in another point.why?

private void pictureBox2_MouseMove(object sender, MouseEventArgs e)
        {
          toolStripStatusLabel2.Text = "X:" + e.X + "," + "Y:" + e.Y;
        }





private void button2_Click(object sender, EventArgs e)
       {



......



......

pictureBox2.Height = 3152;
pictureBox2.Width = 4760;
Graphics g = Graphics.FromImage(pictureBox2.Image);
Pen p = new Pen(Color.Black,9);
g.DrawEllipse(p,m,n,20,20);
pictureBox2.Invalidate();


}

推荐答案

如果args可能在屏幕坐标中,则应在使用它们之前将其转换为客户端坐标.
例如,

the event args might be in screen co-ordinates, you should convert them into client co-ordinates before using them.

for instance,

Point newPt = pictureBox.PointToClient(point);



希望这会有所帮助.



Hope this helps.


PictureBox上进行交互绘制几乎没有任何意义,因为人们尝试使用此组件进行大多数操作.您确实需要使用自定义控件(源自System.Windows.Forms.Control),Panel,甚至在Form上也可以,但在PictureBox上则不需要.如果您抽象出渲染方法(通过在其他介质(例如System.Drawing.Bitmap上进行绘制并保存)),则甚至可以在交互式绘制后保存图像.

要了解有关操作方法的信息,请参阅我过去的回答:
如何从旧图纸中清除面板 [ ^ ].

—SA
Drawing interactively on PictureBox makes little sense, as most of the thing people try to do with this component. You really need to draw on custom control (derived from System.Windows.Forms.Control), Panel, even on Form, but not on PictureBox. You can even save the image after interactive drawing if you abstract out the rendering method (by drawing on other media such as System.Drawing.Bitmap and saving it).

To read about how to do it, please see my past answer:
How do I clear a panel from old drawing[^].

—SA


您可以与此VB进行比较.NET (已测试)和其C#类似物(未测试)通过鼠标程序绘制.
You may compare with this VB.NET (tested) and its C# analog (not tested) drawing by mouse program.


这篇关于图片中点的x和y坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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