2012-09-24 6 views
-1
private void Form2_Load(object sender, EventArgs e) 
    { 
     con1.Open(); 

     Form1 home = new Form1(); 
     home.MdiParent = this.MdiParent ; 

     System.Timers.Timer timer1 = new System.Timers.Timer(); 
     Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.MyComputer) + @"\\server1\KamalSingh\ScreenCaptures"); 
     t.Interval = 500; 
     t.Tick += new EventHandler(StartThread); 
     t.Start(); 
    } 


    System.Windows.Forms.Timer t = new System.Windows.Forms.Timer(); 
    //Thread tt; 

    private static Bitmap bmpscreenshot; 
    private static Graphics gfxscreenshot; 

    void TakeScreenShot() 
    { 

     bmpscreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width,Screen.PrimaryScreen.Bounds.Height,PixelFormat.Format32bppArgb); 
     gfxscreenshot = Graphics.FromImage(bmpscreenshot); 
     gfxscreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X,Screen.PrimaryScreen.Bounds.Y,0,0,Screen.PrimaryScreen.Bounds.Size,CopyPixelOperation.SourceCopy); 
     bmpscreenshot.Save(Environment.GetFolderPath(Environment.SpecialFolder.MyComputer) [email protected]"\\server1\KamalSingh\ScreenCaptures\.bmp", ImageFormat.Png); 
     // tt.Abort(); 
    } 

    protected void StartThread(object sender, EventArgs e) 
    { 
     Thread th = new Thread(new ThreadStart(TakeScreenShot)); 
     th.SetApartmentState(ApartmentState.STA); 
     th.Start(); 
     Thread.Sleep(100); 
     th.Join(); 

    } 

내 프로그램을 실행할 때 발생하는이 오류를 수정하고 싶습니다. 시간이 지나면 오류가 발생합니다.이 오류를 제거하는 방법 GDI +에서 일반 오류가 발생했습니다.

+0

코드 덤프보다는 어떤 일이 일어나는지에 대한 설명을 제공 할 수 있습니까? –

+0

나는 스크린 샷 사진을 폴더에 저장하려고합니다. 또한 스크린 샷 사진은 윈도우 응용 프로그램의 그림 상자에 표시됩니다. 또한 스크린 샷 사진의 크기를 줄이려고합니다. –

답변

0

이 시도 :

void TakeScreenShot() 
{ 

    using(Bitmap bmpscreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width,Screen.PrimaryScreen.Bounds.Height,PixelFormat.Format32bppArgb)) 
    { 
     using(Graphics gfxscreenshot = Graphics.FromImage(bmpscreenshot)) 
     { 
      gfxscreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X,Screen.PrimaryScreen.Bounds.Y,0,0,Screen.PrimaryScreen.Bounds.Size,CopyPixelOperation.SourceCopy); 
      bmpscreenshot.Save(Environment.GetFolderPath(Environment.SpecialFolder.MyComputer) [email protected]"\\server1\KamalSingh\ScreenCaptures\.bmp", ImageFormat.Png); 
     } 
    } 
} 

희망이 도움이!

+0

'Bitmap'은 또한 IIRC 인'IDisposable'을 구현합니다. – Lou

+0

@Dilbert 감사합니다. 글에 올릴 예정입니다. – 3aw5TZetdf

+0

나는 이것을 사용하여 여러 개의 스크린 샷을 폴더에 저장하고 싶습니다. 다른 파일을 저장할 수 있습니다. 여러 파일을 저장하고 싶습니다. –

관련 문제