C#检测用户单击图像/位图的位置
是否可以检测到用户单击加载的图像或C#表单上的位图的位置。只需要它是独立的图像,而不是屏幕位置 好吧,你没有告诉我们你是如何显示图像的,所以我不得不猜测。我假设一个picturebox以其本机分辨率显示图像。因此,在这种情况下:C#检测用户单击图像/位图的位置,c#,winforms,image-processing,C#,Winforms,Image Processing,是否可以检测到用户单击加载的图像或C#表单上的位图的位置。只需要它是独立的图像,而不是屏幕位置 好吧,你没有告诉我们你是如何显示图像的,所以我不得不猜测。我假设一个picturebox以其本机分辨率显示图像。因此,在这种情况下: class MyForm : Form { public MyForm() { picturebox1.MouseDown += picturebox1_MouseDown; } private void
class MyForm : Form
{
public MyForm()
{
picturebox1.MouseDown += picturebox1_MouseDown;
}
private void picturebox1_MouseDown( object sender, MouseEventArgs e )
{
if( (e.Button & MouseButtons.Left) == MouseButtons.Left )
{
var imagePos = e.Location; // that's it
}
}
}
如果你的图像被缩放,你需要做数学运算。获取控件的
宽度
和高度
,并计算它们与图像尺寸之间的比率。将点击位置乘以该比率。好吧,你没有告诉我们你是如何显示图像的,所以我不得不猜测。我假设一个picturebox以其本机分辨率显示图像。因此,在这种情况下:
class MyForm : Form
{
public MyForm()
{
picturebox1.MouseDown += picturebox1_MouseDown;
}
private void picturebox1_MouseDown( object sender, MouseEventArgs e )
{
if( (e.Button & MouseButtons.Left) == MouseButtons.Left )
{
var imagePos = e.Location; // that's it
}
}
}
如果你的图像被缩放,你需要做数学运算。获取控件的
宽度
和高度
,并计算它们与图像尺寸之间的比率。将点击位置乘以该比率。WPF、WinForms、ASP.NET、Silverlight、WP7、…@Sudantha您需要两个或其中一个,因为解决方案会大不相同。@Sudantha的可能重复项-好问题,但这已经在stackoverflow上被多次询问和回答。WPF、WinForms、ASP.NET、Silverlight、WP7,…?@Sudantha您需要两个或其中一个,因为解决方案会有很大的不同。可能是@Sudantha的重复-这是一个好问题,但这已经在stackoverflow上被问了很多次并得到了回答。