2010-04-01 12 views
5

Ho trovato quel codice da qualche parte e lo trovo molto utile ma mi piacerebbe trovare un modo per farlo funzionare in modo da catturare solo l'obiettivo della finestra data. Forse con un ID processo o Nome finestra. Anche se quella finestra non è attiva.VB.NET Cattura schermata finestra (ALT + PRINTSCREEN)

Non voglio rendere attiva quella finestra ma voglio ottenere una cattura dello schermo come se stessi facendo Alt + PrintScreen su di esso.

Ecco il codice che funziona per la piena Screen Capture

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) 

Io uso il Visual Basic 2008 Express

Grazie in anticipo!

+0

possibile duplicato del [Cattura screenshot della finestra attiva?] (Http://stackoverflow.com/questions/1163761/capture-screenshot-of-active-window) – sloth

risposta

1

Guardate questa Capture screenshot of active window? Invece di this.Handle (finestra corrente) si può inserire una maniglia di qualsiasi altra finestra (usando WinAPI funzioni come FindWindow)

1

Questo funziona in vb.net2.0. L'ho appena usato. 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

Il modo più semplice per farlo, anche se è un hack, è questo:

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

Questo vi darà la Alt + Printscreen, mostrando solo davanti maggior parte delle applicazioni.

SendKeys.Send("%{PRTSC}") 

poi continuare come di consueto:

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

Capture the attiva forma.

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 
Problemi correlati