2010-04-01 11 views
5

Znalazłem ten kod gdzieś i uważam, że jest on bardzo użyteczny, ale chciałbym znaleźć sposób, aby działał tak, aby przechwytywał tylko dany cel okna. Może z identyfikatorem procesu lub nazwą okna. Nawet jeśli to okno nie jest aktywne.Przechwytywanie ekranu okna VB.NET (ALT + PRINTSCREEN)

Nie chcę, aby to okno było aktywne, ale chcę zrobić zrzut ekranu, tak jakbym robił na nim Alt + PrintScreen.

Oto kod, który pracuje dla wychwytywania pełnoekranowym

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) 

używam Visual Basic 2008 Express

Z góry dziękuję!

+0

możliwe duplikat [Capture ekranu aktywnego okna?] (Http://stackoverflow.com/questions/1163761/capture-screenshot-of-active-window) – sloth

Odpowiedz

1

Działa to w vb.net2.0. Po prostu go użyłem. 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

Najłatwiej to zrobić, choć jest to hack, jest taka:

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

To daje Alt + Printscreen, pokazując tylko przedni najwięcej aplikacji.

SendKeys.Send("%{PRTSC}") 

Następnie kontynuować normalny sposób:

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

uchwycić aktywną formę.

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 
Powiązane problemy