绘制后,从PictureBox保存图像

时间:2022-07-26 00:24:33

I have PictureBox with an Image , I use the Paint event to draw a line over it , but when I save the image, I get the image without the line been drawn

我有一个带有图像的PictureBox,我使用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");

what am missing here?

这里缺少什么?

1 个解决方案

#1


1  

You want the DrawToBitmap() method:

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

#1


1  

You want the DrawToBitmap() method:

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