2016-04-21 106 views
0

在一個按鈕單擊事件:如何將graphics.copyfromscreen保存到硬盤上的位圖文件?

private void pictureBox1_MouseUp(object sender, MouseEventArgs e) 
     { 
      painting = false; 
      pictureBox2.Invalidate(); 
     } 

然後在漆事件:

private void pictureBox2_Paint(object sender, PaintEventArgs e) 
     { 
      Point pnt; 

      if (rect.Width > 10 && rect.Height > 10) 
      { 
       pnt = PointToScreen(pictureBox1.Location); 
       e.Graphics.Clear(Color.White); 
       e.Graphics.CopyFromScreen(pnt.X + rect.X, pnt.Y + rect.Y, rect.X, rect.Y, new Size(rect.Width, rect.Height)); 
      } 
     } 

我想保存到一個位圖文件而不是整個pictureBox2.Image但只有CopyFromScreen一部分。

這是pictureBox2

截圖

screenshot

在截圖的pictureBox2邊框也是白色的圖像周圍。但是我想只保存圖片而不是整個pictureBox2.Image,並且在pictureBox2繪畫事件可能在按鈕單擊事件之前執行它。所以圖片只會保存到位圖中。

+1

你可以使用'pictureBox.Image.Save();'? – Jacobr365

回答

相關問題