【发布时间】:2012-04-06 19:31:46
【问题描述】:
如何使用光标在图片框中获取像素x 和y?
【问题讨论】:
-
将其 Image 属性转换回位图并使用 GetPixel()。
-
你是指鼠标指针下像素的颜色吗?
标签: c# winforms bitmap picturebox mouse-cursor
如何使用光标在图片框中获取像素x 和y?
【问题讨论】:
标签: c# winforms bitmap picturebox mouse-cursor
如果要获取点击像素的颜色:
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);
}
【讨论】:
图片框无法获取像素。但它包含的图像可用于创建具有 getpixel 函数的bitmap 对象。然而,我要提一下,这不是最快的操作。如果您需要它快速,我会查看 GDI win32 函数。
【讨论】: