How can I get pixel x
and y
in a picturebox using the cursor?
If you want to get the color of the clicked pixel:
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With