Please, please, do not do that!
Every time you move the mouse (and that can be a hundred or more times a second) you are creating a new bitmap the same as the existing one! And you don't dispose of it, so it is hanging around until the Garbage Collector comes along to get rid of it.
I cannot think of a single less efficient way to do that!
Fiurstly, if you create a bitmap, you are responbsible for Disposing it, either explicitly, or by creating it in a
using
block:
using(Bitmap b = new Bitmap(pictureBox1.Image))
{
if (e.X >= 0 && e.X <= b.Width && e.Y >= 0 && e.Y <= b.Height)
{
Color c = b.GetPixel(e.X, e.Y);
mouseCOL.Text = "R : " + c.R.ToString() + " G : " + c.G.ToString()
+ " B : " + c.B.ToString();
}
}
But a better idea is not to create a new one at all:
Bitmap b = (Bitmap) pictureBox1.Image;
if (e.X >= 0 && e.X <= b.Width && e.Y >= 0 && e.Y <= b.Height)
{
Color c = b.GetPixel(e.X, e.Y);
mouseCOL.Text = "R : " + c.R.ToString() + " G : " + c.G.ToString()
+ " B : " + c.B.ToString();
}
The rest of your problem I don't understand at all - it's probably a language thing, but please try top give us the actual error message, and indicate on which line you are getting it.