2016-09-06 26 views
0

我想下面的代碼來捕捉截圖:問題,同時節省截圖

Bitmap bitmap = new Bitmap (Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); 

    Graphics graphics = Graphics.FromImage(bitmap as System.Drawing.Image); 
    graphics.CopyFromScreen(25, 25, 25, 25, bitmap.Size); 

    bitmap.Save("C:\\Users\\Mayank\\Desktop\\Screenshot\\", ImageFormat.Bmp); 

最後一行導致到以下錯誤:發生在GDI 一般性錯誤+

請幫助:)

+2

bitmap.Save應該得到一個文件不是目錄。你嘗試過嗎? –

回答

0
int width=800;int height=480; 
using (Bitmap bmpScreenCapture = new Bitmap(width,height)) 
{ 
using (Graphics g = Graphics.FromImage(bmpScreenCapture)) 
{ 
g.CopyFromScreen(0,0,0, 0,bmpScreenCapture.Size,CopyPixelOperation.SourceCopy);bmpScreenCapture.Save("test.png"); 
} 
} 
+0

仍然導致相同的錯誤。 –

+0

[GDI +中的一般錯誤出現在屏幕截圖中](http://stackoverflow.com/a/15971438/3060520) –

-1

解決了這個問題。問題在於我提供文件路徑和名稱的方式。解決它與以下代碼:

bmpScreenCapture.Save(@"C:\Users\Mayank\Desktop\Screenshot\TestFile.bmp");