Hai friends.
I need to get pixel value at runtime when clicking mouse event .please tell me if any sample code available.
thank you
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
FroglegPosted May 4, 2012, 5:30 AM
Add picturebox and label to form
code:
public partial class Form1 : Form
{
Bitmap mybitmap;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
loadImage();
}
public void loadImage()
{
Image img = Image.FromFile("head1.png");//use your own image
mybitmap = new Bitmap(img.Width, img.Height);
Graphics g = Graphics.FromImage(mybitmap);
g.DrawImage(img, 0, 0);
img.Dispose();
pictureBox1.Image = mybitmap;
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
Color pixelColor = mybitmap.GetPixel(e.X, e.Y);
label1.BackColor = pixelColor;
}
}