2010-04-01 133 views
5

我發現代碼的某處,我覺得它非常有用,但我想找到一種方法使其工作,因此它只捕獲給定的窗口目標。可能帶有processID或Window Name。即使該窗口不活動。VB.NET窗口屏幕捕獲(ALT + PRINTSCREEN)

我不想讓這個窗口處於活動狀態,但想要獲得一個屏幕截圖,就像我在做Alt + PrintScreen一樣。

這裏是一個全屏幕捕捉作品的代碼

Private bmpScreenShot As Bitmap 
    Private gfxScreenshot As Graphics 

    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(fileName, ImageFormat.Png) 

我使用Visual Basic 2008速成

預先感謝您!

+0

可能重複的[活動窗口捕獲截圖?](http://stackoverflow.com/questions/1163761/capture-screenshot-of-active-window) – sloth 2014-04-14 13:24:16

回答

1

這個作品在vb.net2.0插入任何其他窗口的句柄。我只是用它。 Here is the source code.

Dim SC As New ScreenShot.ScreenCapture 

    'captures entire desktop straight to file 
    SC.CaptureScreenToFile("c:\accops\test\desktop2.jpg", Imaging.ImageFormat.Jpeg) 
0

最簡單的方式做到這一點,雖然這是一個黑客,是這樣的:

SendKeys.Send("{PRTSC}") 
Dim Screenshot As Image = Clipboard.GetImage() 
Screenshot.Save("c:\ScreenShot.jpg", System.Drawing.Imaging.ImageFormat.Jpeg) 
1

這會給你的Alt + Printscreen,只顯示最前應用。

SendKeys.Send("%{PRTSC}") 

然後繼續以正常的方式:

Dim Screenshot As Image = Clipboard.GetImage() 
Screenshot.Save("c:\ScreenShot.jpg", System.Drawing.Imaging.ImageFormat.Jpeg) 
0

捕獲活動形式。

Private Sub tsbCamera_Click(sender As Object, e As EventArgs) Handles tsbCamera.Click 
    Dim bm As New Bitmap(Width, Height) 
    DrawToBitmap(bm, New Rectangle(0, 0, Width, Height)) 
    Dim name As String = InputBox("Name it:") 
    bm.Save(Application.StartupPath & "\ScreenShot\" & name & ".png", System.Drawing.Imaging.ImageFormat.Png) 
End Sub