Ich bin auf der Suche nach einem guten. NET-basierte Screen Capture-Dienstprogramm. Es müsste in der Lage sein, sichere Seiten (https) zu erfassen. Es wäre vorzuziehen, dass es Flash/ActiveX erfasst..Net Browser-Bildschirm-Capture-Dienstprogramm
Antwort
Wenn suchen diese von Code zu tun, dann können Sie die Graphics.CopyFromScreen Methode verwenden, wie hier beschrieben: here
Das WebBrowser-Steuerelement hat eine DrawToBitmap Funktion, aber es funktioniert nicht gut. Ich empfehle es nicht.
Eine weitere Option ist die Verwendung von Graphics.CopyFromScreen, zuverlässig, aber das Fenster muss oben sein, was lästig ist.
Die beste Lösung ist die Verwendung von PrintWindow. Es funktioniert bei Fenstern im Hintergrund, aber nicht bei minimierten Fenstern und manchmal nicht bei Fenstern, die am Rand des Bildschirms hängen. Dieser Code wird von Task Switcher genommen, eine Microsoft-Anwendung, die die Standard-Windows-Alt-Tab ersetzt:
Public Function CaptureScreen(ByVal R As Rectangle) As Bitmap
Dim b As New Bitmap(R.Width, R.Height)
Dim g As Graphics = Graphics.FromImage(b)
Dim hdc As IntPtr = GetWindowDC(Me.Handle)
If hdc <> IntPtr.Zero Then
Dim hdcMem As IntPtr = CreateCompatibleDC(hdc)
If hdcMem <> IntPtr.Zero Then
Dim hbitmap As IntPtr = CreateCompatibleBitmap(hdc, Me.Width, Me.Height)
If hbitmap <> IntPtr.Zero Then
SelectObject(hdcMem, hbitmap)
PrintWindow(Me.Handle, hdcMem, 0)
BitBlt(g.GetHdc, 0, 0, b.Width, b.Height, hdcMem, R.X, R.Y, TernaryRasterOperations.SRCCOPY)
g.ReleaseHdc()
DeleteObject(hbitmap)
End If
DeleteDC(hdcMem)
End If
ReleaseDC(Me.Handle, hdc)
End If
Return b
End Function
Sie erhalten alle, die Windows-API definieren müssen. Dies sind die VB-Stil Erklärungen, genommen von PInvoke:
''' <summary>
''' Performs a bit-block transfer of the color data corresponding to a
''' rectangle of pixels from the specified source device context into
''' a destination device context.
''' </summary>
''' <param name="hdc">Handle to the destination device context.</param>
''' <param name="nXDest">The leftmost x-coordinate of the destination rectangle (in pixels).</param>
''' <param name="nYDest">The topmost y-coordinate of the destination rectangle (in pixels).</param>
''' <param name="nWidth">The width of the source and destination rectangles (in pixels).</param>
''' <param name="nHeight">The height of the source and the destination rectangles (in pixels).</param>
''' <param name="hdcSrc">Handle to the source device context.</param>
''' <param name="nXSrc">The leftmost x-coordinate of the source rectangle (in pixels).</param>
''' <param name="nYSrc">The topmost y-coordinate of the source rectangle (in pixels).</param>
''' <param name="dwRop">A raster-operation code.</param>
''' <returns>
''' <c>true</c> if the operation succeeded, <c>false</c> otherwise.
''' </returns>
<DllImport("gdi32.dll")> _
Private Shared Function BitBlt(ByVal hdc As IntPtr, ByVal nXDest As Integer, ByVal nYDest As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hdcSrc As IntPtr, ByVal nXSrc As Integer, ByVal nYSrc As Integer, ByVal dwRop As TernaryRasterOperations) As Boolean
End Function
Private Declare Function PrintWindow Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal hdcBlt As IntPtr, ByVal nFlags As Integer) As Boolean
Private Declare Function CreateCompatibleDC Lib "gdi32.dll" (ByVal hdc As IntPtr) As IntPtr
Private Declare Function DeleteDC Lib "gdi32.dll" (ByVal hdc As IntPtr) As Boolean
Private Declare Function CreateCompatibleBitmap Lib "gdi32.dll" (ByVal hdc As IntPtr, ByVal nWidth As Integer, ByVal nHeight As Integer) As IntPtr
Private Declare Function SelectObject Lib "gdi32.dll" (ByVal hdc As IntPtr, ByVal hgdiobj As IntPtr) As IntPtr
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As IntPtr) As Boolean
Private Declare Function GetWindowDC Lib "user32" (ByVal hWnd As IntPtr) As IntPtr
Private Declare Function ReleaseDC Lib "user32" (ByVal hWnd As IntPtr, ByVal hDC As IntPtr) As Integer
Public Enum TernaryRasterOperations
SRCCOPY = &HCC0020 'dest = source
SRCPAINT = &HEE0086 'dest = source OR dest
SRCAND = &H8800C6 'dest = source AND dest
SRCINVERT = &H660046 'dest = source XOR dest
SRCERASE = &H440328 'dest = source AND (NOT dest)
NOTSRCCOPY = &H330008 'dest = (NOT source)
NOTSRCERASE = &H1100A6 'dest = (NOT src) AND (NOT dest)
MERGECOPY = &HC000CA 'dest = (source AND pattern)
MERGEPAINT = &HBB0226 'dest = (NOT source) OR dest
PATCOPY = &HF00021 'dest = pattern
PATPAINT = &HFB0A09 'dest = DPSnoo
PATINVERT = &H5A0049 'dest = pattern XOR dest
DSTINVERT = &H550009 'dest = (NOT dest)
BLACKNESS = &H42 'dest = BLACK
WHITENESS = &HFF0062 'dest = WHITE
End Enum
Können Sie etwas mehr erweitern, was Sie erfassen möchten? Möchten Sie Standbilder oder Filme? Möchten Sie den gesamten Bildschirm oder nur einen Bereich? – ChrisF