从面板中绘制bmp可以保存空图像c#

时间:2015-03-10 07:56:13

标签: c# panel save-image

我正在尝试将矩形绘制到面板中,然后将其保存到位图中。屏幕显示我已经成功绘制了矩形但是当我查看保存的位图时,它们是空的白色矩形。

                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);

0 个答案:

没有答案