2013-04-12 7 views
0

화면 캡처를하는 응용 프로그램을 작성하고 있지만 임의로 GDI + 일반 오류가 발생합니다. 불행히도 일반적인 오류는 디버깅에 도움이되지 않습니다.GDI +의 일반 오류가 화면 캡처에서 발생합니다.

static void CaptureScreen() 
    { 
     bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb); 
     // Create a graphics object from the bitmap 
     gfxScreenshot = Graphics.FromImage(bmpScreenshot); 
     // Take the screenshot from the upper left corner to the right bottom corner 
     gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy); 
     // Save the screenshot to the specified path that the user has chosen 
     bmpScreenshot.Save(savePath + "img" + times.ToString()+ ".png", ImageFormat.Png); 
    } 

가끔 나에게 일반 오류를 줄 것이다, 그래서 나는

static void CaptureScreen() 
    { 
     bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb); 
     // Create a graphics object from the bitmap 
     gfxScreenshot = Graphics.FromImage(bmpScreenshot); 
     // Take the screenshot from the upper left corner to the right bottom corner 
     gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy); 
     // Save the screenshot to the specified path that the user has chosen 
     bmpScreenshot.Save(savePath + "img" + times.ToString()+ ".png", ImageFormat.Png); 

     bmpScreenshot.Dispose(); 
     gfxScreenshot.Dispose(); 
    } 

을 "어쩌면 나는 비트 맵과 변수 그래픽을 처리해야한다"다음 삭제를 생각 파일을 말했다 : 화면 캡처에 대한 나의 코드입니다 :

  for (int i = 1; i == times; i++) 
      { 
       File.Delete(savePath + @"\img" + i.ToString() + ".png"); 
      } 
      times = 0; 

하지만 두 번 실행하면 동일한 파일에 쓰는 경우 파일이 사용 중이라고 표시됩니다. 어떤 아이디어?

+0

는 "일반 GDI + 오류"에 대한 SO 검색 했습니까? 당신은 놀랄 것입니다 ... –

+0

@ThorstenDittmar StackOverflow를 검색했지만 유사한 메소드 호출이있는 것을 찾을 수 없습니다. 어쩌면 나는 열심히 수색하지 않았을 것이다, 그렇다면 사과한다. – Thegluestickman

답변

0

도움말 수 다음

using (bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb)) 
using (gfxScreenshot = Graphics.FromImage(bmpScreenshot)) 
{ 
    // Take the screenshot from the upper left corner to the right bottom corner 
    gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy); 

    Bitmap bmpScreenshot2 = new Bitmap(bmpScreenshot); // FIX: Change "S" to "s"... 
    // Save the screenshot to the specified path that the user has chosen 
    bmpScreenshot2.Save(savePath + "img" + times.ToString()+ ".png", ImageFormat.Png); 
} 
+0

"현재 컨텍스트에 bmpScreenShot이 없습니다" 비트 맵 bmpScreenshot2 = 새 비트 맵 (bmpScreenShot); – Thegluestickman

+0

나는이 문제를 직접 해결할 수 있다고 생각한다. 나는 코드를 고치겠다. –

+0

아, 나도 그걸 알아 차리지 못 했어 : P 너의 모든 도움에 감사드립니다! – Thegluestickman

관련 문제