Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello .. i'm beginner in C# and i just want to ask about to show the pixel value for each pixel in a bitmap picture

I've used the code below to open a bitmap picture:

C#
private void pictureBox1_Click(object sender, EventArgs e)
{
    OpenFileDialog dlg = new OpenFileDialog();
    dlg.Title = "Open Image";
    dlg.Filter = "bmp files (*.bmp)|*.bmp";
    if (dlg.ShowDialog() == DialogResult.OK)
    {
        pictureBox1.Image = Image.FromFile(dlg.FileName);
    }
    dlg.Dispose();

}

How can i modify it to show the pixel value in a label ?
Posted
Updated 16-Oct-14 23:54pm
v2
Comments
Leo Chapiro 17-Oct-14 5:56am    
Not clear what you want to achieve. What do you mean by "pixel value"?
Ali Gad 17-Oct-14 6:51am    
Each of the pixels that represents an image stored inside a computer has a pixel value which describes how bright that pixel is .. i want to show this value
Ali Gad 17-Oct-14 6:51am    
i want a label that shows value of each pixel when i move with the mouse in the picture
BillWoodruff 17-Oct-14 13:27pm    
Do you know how to detect the mouse moving over the PictureBox ?
Ali Gad 17-Oct-14 14:23pm    
no

Not sure what you mean by showing the pixel value, but to get the pixel value for a given coordinate you can use Bitmap.GetPixel[^]
 
Share this answer
 
Comments
Ali Gad 17-Oct-14 6:43am    
i want a label that shows value of each pixel when i move with the mouse in the picture
BillWoodruff 17-Oct-14 13:27pm    
So, study the article George referred you to and use the code sample there as a basis for your code.
George Jonsson 18-Oct-14 9:35am    
That would have been useful info in your original question.
Look at solution 2 and you should be able to solve your problem.
BillWoodruff 17-Oct-14 13:26pm    
+5
Assume:

0. you have WinForm, 'FrmViewColors

1. you have a PictureBox on a Form with its 'Image property set, 'pbxViewColors

2. you have a Label on the Form, 'lblColor

3. you create an EventHandler for the MouseMove Event of the PictureBox

C#
private Bitmap bmp;

private void FrmViewColors_Load(object sender, EventArgs e)
{
    // get the Bitmap from the PictureBox Image
    bmp = // left for you to figure out
}

// EventHandler
private void pbxViewColors_MouseMove(object sender, MouseEventArgs e)
{
    Color clr = bmp.GetPixel(e.X, e.Y);

    lblColor.Text = // left for you to figure out
}
 
Share this answer
 
Comments
George Jonsson 18-Oct-14 9:33am    
Good hints. +5
Ali Gad 19-Oct-14 5:43am    
couldn't solve it .. i just tried to update my code with your hints but the label finally doesn"t show anything

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900