C# 绘图后从PictureBox保存图像

C# 绘图后从PictureBox保存图像,c#,image,winforms,picturebox,C#,Image,Winforms,Picturebox,我有PictureBox和Image,我使用Paint事件在上面画一条线,但是当我保存图像时,我得到的图像没有画线 private void PicBox_Paint(object sender, PaintEventArgs e) { e.Graphics.DrawLine(pen, end, start); e.Graphics.Flush(); e.Graphics.Save(); } //and I save i

我有
PictureBox
Image
,我使用
Paint
事件在上面画一条线,但是当我保存图像时,我得到的图像没有画线

    private void PicBox_Paint(object sender, PaintEventArgs e)
    {
        e.Graphics.DrawLine(pen, end, start);
        e.Graphics.Flush();
        e.Graphics.Save();
    } 

//and I save it like this
picBox.Image.Save("directory");
我这里缺少什么?

您想要的方法是:


在它上面画的线是程序吗?@kevin628你是什么意思?是的,它是画出来的,我可以看到它,但是当我保存它时,它只是没有线条的图像…添加到@Idle(几乎正确)回答:既不
e.Graphics.Flush()
也不
e.Graphics.save()
应该在那里!您可能认为它的功能也不一样。`Bitmap bmp=新位图(picBox.Image.Width,picBox.Image.Height);DrawToBitmap(bmp,新矩形(0,0,picBox.Image.Width,picBox.Image.Height));`它给了我一个错误,无效的参数为什么!?请使该
Bitmap bmp=新位图(picBox.ClientSize.Width,picBox.ClientSize.Height)
    private void button1_Click(object sender, EventArgs e)
    {
        Bitmap bmp = new Bitmap(picBox.ClientSize.Width, picBox.ClientSize.Height);
        picBox.DrawToBitmap(bmp, picBox.ClientRectangle);
        bmp.Save("...fileName Here...");
    }