C#用光标获取图片框中的像素?

时间:2012-04-06 19:31:46

标签: c# winforms bitmap cursor picturebox

如何使用光标在图片框中获取像素xy

2 个答案:

答案 0 :(得分:15)

如果您想获得点击像素的颜色:

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);
}

答案 1 :(得分:5)

图片框无法获取像素。但它包含的图像可用于创建具有getpixel函数的bitmap对象。不过我会提到这不是最快的操作。如果你需要快速,我会看看GID win32功能。