|
|
我想对某些朋友可能有用。
.Net Framework并不万能,还是得用上API。
Public Class ScrCap
Private Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" (ByVal lpDriverName As String, ByVal lpDeviceName As String, ByVal lpOutput As String, ByVal lpInitData As Int32) As Int32
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Integer, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hSrcDC As Integer, ByVal xSrc As Integer, ByVal ySrc As Integer, ByVal dwRop As Integer) As Integer
'将指定屏幕区域内容保存到Bitmap对象
Public Function CaptureScreenToBitmap(ByVal Left As Int32, ByVal Top As Int32, ByVal Width As Int32, ByVal Height As Int32) As Bitmap
Dim DisplayDC As New IntPtr(CreateDC("DISPLAY", Nothing, Nothing, 0))
Dim G1 As Graphics = Graphics.FromHdc(DisplayDC)
Dim Bmp As New Bitmap(Width, Height, G1)
Dim G2 As Graphics = Graphics.FromImage(Bmp)
Dim BmpDC As IntPtr = G2.GetHdc()
BitBlt(BmpDC.ToInt32, 0, 0, Width, Height, DisplayDC.ToInt32, Left, Top, &HCC0020)
G2.ReleaseHdc(BmpDC)
DisplayDC = Nothing
Return Bmp
End Function
End Class |
|