那你就在按钮里重新执行
Graphics g = pictureBox1.CreateGraphics();
并把它画到一个新建Image里,然后save

解决方案 »

  1.   

    Graphics g = pictureBox1.CreateGraphics();
    //Graphics g = Graphics.FromImage(this.pictureBox1.Image);被你注释掉的那句不就可以么,不要创建 Graphics
    另外 Graphics 的 Dispose 不要忘了
      

  2.   

    不要在MouseMove里面CreateGraphics,它会导致GDI资源泄露,一定时间后可能会导致程序崩溃等。
    用this.pictureBox1.Invalidate来强迫它更新。
    用数据结构(那些currentScribble ,scribbles)等来保存自定义标志,并在更新,或存图的时候重画。
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.pictureBox1.Paint += pictureBox1_Paint;  // 可以移动到设计器生成代码里
        }    private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            currentScribble = new List<Point>();
            currentScribble.Add(e.Location);
        }    private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left && this.currentScribble != null)
            {
                currentScribble.Add(e.Location);
                RedrawPictureBox();
            }
        }    List<Point> currentScribble = null;
        List<Point[]> scribbles = new List<Point[]>();
        void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
            using (Pen pen = new Pen(Color.Blue, 2))
            {
                foreach (Point[] points in scribbles)
                {
                    e.Graphics.DrawLines(pen, points);
                }
                if (this.currentScribble != null)
                {
                    e.Graphics.DrawLines(pen, this.currentScribble.ToArray());
                }
            }
        }    private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
        {
            if (currentScribble != null && currentScribble.Count > 1)
            {
                RedrawPictureBox();
                this.scribbles.Add(currentScribble.ToArray());
            }
            this.currentScribble = null;
        }    private void RedrawPictureBox()
        {
            if (currentScribble.Count >= 2)
            {
                Rectangle last = new Rectangle(currentScribble[currentScribble.Count - 2], Size.Empty);
                Rectangle current = new Rectangle(currentScribble[currentScribble.Count - 1], Size.Empty);
                Rectangle invalidateArea = Rectangle.Inflate(Rectangle.Union(last, current), 2, 2);
                this.pictureBox1.Invalidate(invalidateArea);
            }
        }    private void button5_Click(object sender, EventArgs e)
        {
            Rectangle rect = new Rectangle(Point.Empty, this.pictureBox1.Size);
            using (Bitmap bmp = new Bitmap(rect.Width, rect.Height))
            {
                this.pictureBox1.DrawToBitmap(bmp, rect);  // 画pictureBox1显示的图,假定它没有边框
                using (Graphics g = Graphics.FromImage(bmp))
                {
                    pictureBox1_Paint(this, new PaintEventArgs(g, rect)); // 画自定义标记
                }
                bmp.Save(@"D:\2.jpg", ImageFormat.Jpeg);
            }
            MessageBox.Show("ok");
        }
    }