我正在尝试将矩形绘制到面板中,然后将其保存到位图中。屏幕显示我已经成功绘制了矩形但是当我查看保存的位图时,它们是空的白色矩形。
System.Drawing.Graphics graphicsObj;
graphicsObj = panel1.CreateGraphics();
Pen myPen = new Pen(System.Drawing.Color.Black, 1);
System.Drawing.Rectangle myRectangle = new System.Drawing.Rectangle(x, y, 50, 50);
greenBrush = new SolidBrush(Color.MediumVioletRed);
graphicsObj.FillRectangle(greenBrush, myRectangle);
graphicsObj.DrawString("SomeString", new System.Drawing.Font
("Arial", 12), Brushes.Blue, myRectangle);
graphicsObj.DrawRectangle(myPen, myRectangle);
string dir = Directory.GetCurrentDirectory();
string img = t.Field<int>("ID").ToString() + ".png";
string total = dir + "\\pics\\" + img;
Bitmap bmp = new Bitmap(panel1.ClientRectangle.Width,
panel1.ClientRectangle.Height);
panel1.DrawToBitmap(bmp, panel1.ClientRectangle);
string dira = Directory.GetCurrentDirectory();
string imga = t.Field<int>("ID").ToString() + "cal.bmp";
string totala = dira + "\\pics\\" + imga;
bmp.Save(totala);