2011-05-21 211 views
0

可能重複:
.NET Equivalent of Snipping Tool如何抓取屏幕截圖的預定義區域座標值?

我下面的代碼正在爲整個屏幕截圖,但我想採取截圖與預先設定的區域。我更喜歡點擊一個按鈕,然後拖動並選擇我想抓取x,y,destinationX,destinationY值的區域。有人可以給我一個提示或示例如何做到這一點?

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); 

回答

0

我還沒有真正做了很多位圖/圖形工作,但你能不能簡單地捕捉到X,該MOUSE_DOWN的Y座標和MOUSE_UP事件,然後使用這些在你的CopyFromScreen方法

東西例如:

private void Form1_MouseDown(object sender, MouseEventArgs e) 
    { 
     startX = e.X; 
     startY = e.Y; 
    } 

    private void Form1_MouseUp(object sender, MouseEventArgs e) 
    { 
     endX = e.X; 
     endY = e.Y; 
    } 

然後,您可以做一些小算術以確定要傳輸的區域的大小,並將其填充到您的方法中。