我正在寻找一个好的基于.NET的屏幕捕获实用程序。它需要能够捕获安全页面(https)。最好是捕获Flash / ActiveX。
答案 0 :(得分:1)
如果要从代码中执行此操作,则可以使用此处所述的Graphics.CopyFromScreen方法:here
答案 1 :(得分:0)
答案 2 :(得分:0)
WebBrowser控件具有DrawToBitmap功能,但效果不佳。我不推荐它。
另一种选择是使用Graphics.CopyFromScreen,可靠但窗口必须是最顶层的,这很烦人。
最佳解决方案是使用PrintWindow。它可以在后台的窗口上工作,但不能在最小化的窗口上工作,有时也不会在挂在屏幕边缘的窗口上工作。此代码取自Task Switcher,这是一个替换默认Windows Alt-Tab的Microsoft应用程序:
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
您需要定义所有Windows API。这些是VB样式声明,取自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