I don't have any problem saving panel as image with UI thread but i have only a black rectangle when i save this panel at another thread except UI thread :
using (Bitmap bmp = new Bitmap(panel1.Width, panel1.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb))
{
if (panel1.InvokeRequired)
{
panel1.BeginInvoke((MethodInvoker)delegate ()
{
panel1.DrawToBitmap(bmp, new System.Drawing.Rectangle(Point.Empty, bmp.Size));
});
Bitmap bb = bmp.Clone(new System.Drawing.Rectangle(0, 0, 1016, 648), PixelFormat.Format24bppRgb);
bb.Save(@"C:sample.bmp", ImageFormat.Bmp);
}
else
{
panel1.DrawToBitmap(bmp, new System.Drawing.Rectangle(Point.Empty, bmp.Size));
Bitmap bb = bmp.Clone(new System.Drawing.Rectangle(0, 0, 1016, 648), PixelFormat.Format24bppRgb);
bb.Save(@"C:sample.bmp", ImageFormat.Bmp);
}
}
This problem is related with locking mechanism? Or how can i solve this problem?
Thanks in advance.
See Question&Answers more detail:os