如何使用鼠标光标在图片框中获取像素点 x
和 y
的位置?
如何使用鼠标光标在图片框中获取像素点 x
和 y
的位置?
如果您想获取所点击像素的颜色:
Color pixelColor;
// add the mouse click event handler in designer mode or:
// myPicturebox.MouseClick += new MouseEventHandler(myPicturebox_MouseClick);
private void myPicturebox_MouseClick(object sender, MouseEventArgs e) {
if (e.Button == MouseButtons.Left)
pixelColor = GetColorAt(e.Location);
}
private Color GetColorAt(Point point) {
return ((Bitmap)myPicturebox.Image).GetPixel(point.X, point.Y);
}