我是在图片框(pictureBox1)中画了一图形. 我想当它绘制的时候 也可以保存到文件中private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphicse;
            Pen p1 = new Pen(Color.Red);  
    
            g.FillRectangle(p1, 100, 100, 100, 100);           // -----------------创建图象---------------
            Bitmap pic = new Bitmap(500, 500, g);
            pic.Save("c:\\me.bmp", ImageFormat.Bmp);
          
        }     为什么不行呢?? 有什么方法,可以把自己定义的图形保存在文件里呢??
  请高手帮忙!!!谢谢!

解决方案 »

  1.   

    private void save
    {
    Bitmap pic  = new Bitmap(500, 500);
    g = Graphics.FromImage(pic  );
    Pen p1 = new Pen(Color.Red);  
    g.FillRectangle(p1, 100, 100, 100, 100);
    pic.Save("c:\\me.bmp", ImageFormat.Bmp);}
    看看这样的行不行,没装vs,帮不了什么
      

  2.   


    可以了,谢谢了private void Draw()
            {
                Pen p = new Pen(Color.Red, 1);
                Bitmap pic = new Bitmap(380, 300);
                Graphics g = Graphics.FromImage(pic);
                const double Pi = 3.1415926;
                int x1, x2, y1, y2;
                double a, d;
                for (a = 0; a <= 2 * Pi; a += Pi/ 90)
                {
                    d = 60 + 90 * Math.Sin(8 * a);
                    x1 = (int)(300 * Math.Cos(a));
                    y1 = (int)(90* Math.Sin(a));
                    x2 = (int)(d * Math.Cos(a));
                    y2 = (int)(60 * Math.Sin(a));
                    x1 = x1 + 420;
                    x2 = x2 +420;
                    y1 = -y1 + 160;
                    y2 = -y2 + 160;
                    g.DrawLine(p, x1 / 2, y1, x2 / 2, y2 );
                }
                pic.Save("c:\\me.bmp", ImageFormat.Bmp);
                g.Dispose();
            }