2015-07-11 113 views
0

我有PictureBoxImage,我用的是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"); 
图像

这里错过了什么?

+0

是行画过它的程序? – kevin628

+0

@ kevin628你是什么意思?是的,它是绘制的,我可以看到它,但是当我保存它只是没有线的图像... – Abanoub

+0

添加到@空闲的(几乎正确)的答案:既不'e.Graphics.Flush()'也没有'e.Graphics。保存()'应该在那里!你也许不会这么想。 – TaW

回答

1

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

'Bitmap bmp = new Bitmap(picBox.Image.Width,picBox.Image.Height); picBox.DrawToBitmap(bmp,new Rectangle(0,0,picBox.Image.Width,picBox.Image.Height));'它给了我一个错误,无效的参数为什么? – Abanoub

+1

我没有收到你刚刚发布的代码片段的错误... –

+0

请使'Bitmap bmp = new Bitmap(picBox.ClientSize.Width,picBox.ClientSize.Height)''! – TaW