Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# getting pixels in picturebox with cursor? [closed]

How can I get pixel x and y in a picturebox using the cursor?

like image 582
xFireTR Avatar asked Nov 30 '22 06:11

xFireTR


1 Answers

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);
}
like image 125
Omar Avatar answered Dec 04 '22 22:12

Omar