绘制后,从PictureBox保存图像

时间:2015-07-11 01:22:36

标签: 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 it like this
picBox.Image.Save("directory");

这里缺少什么?

1 个答案:

答案 0 :(得分:2)

您需要DrawToBitmap()方法:

    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...");
    }