I have a panel and I use it's Graphics gr = panel1.CreateGraphics() to draw lines and other stuff. I need to get pixel color of the point where mouse is clicked, so I decided to use GetPixel method of Bitmap. I create bitmap this way:
Bitmap b = new Bitmap(width, height);
panel1.DrawToBitmap(b, new Rectangle(0, 0, width, height));
b.Save("D:/aaa.bmp");
but I get only white rectangle even if I've drawn anything. What's the problem?
Only things that are drawn in the
Paint
event will be rendered byDrawToBitmap
. Instead of explicitly callpanel1.CreateGraphics()
, handle thePaint
event of the panel and do your drawing usinge.Graphics
.