vb如何截取固定位置大小的图片

来源:百度知道 编辑:UC知道 时间:2024/06/22 15:40:12
我有截取桌面的
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function DrawIcon Lib "user32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal hIcon As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long

Private Sub form_Load()
Dim hdc As Long
Dim sw As Integer
Dim sh As Integer
Dim CurPos As POINTAPI
Dim Cur As Long
Me.Hide
DoEvents
Pictu

Private Function Capture(P1 As POINTAPI, P2 As POINTAPI)
Dim hdc As Long
Dim sw1, sw2 As Integer
Dim sh1, sh2 As Integer
Dim CurPos As POINTAPI
Dim Cur As Long
Me.Hide
DoEvents
Picture1.AutoRedraw = True
hdc = GetDC(0)
GetCursorPos CurPos
Cur = GetCursor
Picture1.Width = Screen.Width
Picture1.Height = Screen.Height

BitBlt Picture1.hdc, 0, 0, P2.x - P1.x, P2.y - P1.y, hdc, P1.x, P1.y, vbSrcCopy
Me.Show
DrawIcon Picture1.hdc, 0, 0, Cur
ReleaseDC 0, hdc
Picture1.AutoRedraw = False

End Function
这是我曾经做的一个截图的函数,或许对你有帮助,P1,P2为截图的左上,右下坐标,程序需要添加一个PICTURE控件

修改bitblt参数