C # get pixels in a picture using cursor?

How can I get the pixel x

and y

in the frame using the cursor?

+3


source to share


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

      

+14


source


There is no way to get the pixel in the image window. But the contained image can be used to create a bitmap object that has a getpixel function. I would say, however, that it is not the fastest of the operations. If you need it to be fast, I would look at the win32 GID features.



+4


source







All Articles