111,130
社区成员
发帖
与我相关
我的任务
分享 Private Declare Function CreateCompatibleDC Lib "GDI32" (ByVal hDC As Integer) As Integer
Private Declare Function CreateCompatibleBitmap Lib "GDI32" (ByVal hDC As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer) As Integer
Private Declare Function SelectObject Lib "GDI32" (ByVal hDC As Integer, ByVal hObject As Integer) As Integer
Private Declare Function BitBlt Lib "GDI32" (ByVal srchDC As Integer, ByVal srcX As Integer, ByVal srcY As Integer, ByVal srcW As Integer, ByVal srcH As Integer, ByVal desthDC As Integer, ByVal destX As Integer, ByVal destY As Integer, ByVal op As Integer) As Integer
Private Declare Function DeleteDC Lib "GDI32" (ByVal hDC As Integer) As Integer
Private Declare Function DeleteObject Lib "GDI32" (ByVal hObj As Integer) As Integer
Declare Function GetDC Lib "user32" Alias "GetDC" (ByVal hwnd As Integer) As Integer
Const SRCCOPY As Integer = &HCC0020
Private Sub MyPrint(ByVal startPoint As Point, ByVal endPoint As Point)
Dim bmp As Bitmap
Dim hDC, hMDC As Integer
Dim hBMP, hBMPOld As Integer
hDC = GetDC(0)
hMDC = CreateCompatibleDC(hDC)
hBMP = CreateCompatibleBitmap(hDC, Me.Width, Me.Height)
hBMPOld = SelectObject(hMDC, hBMP)
BitBlt(hMDC, 0, 0, endPoint.X - startPoint.X, endPoint.Y - startPoint.Y, hDC, startPoint.X, startPoint.Y, SRCCOPY)
hBMP = SelectObject(hMDC, hBMPOld)
bmp = Image.FromHbitmap(New IntPtr(hBMP))
DeleteDC(hDC)
DeleteDC(hMDC)
DeleteObject(hBMP)
Dim ofd As New SaveFileDialog
ofd.Filter = "jpg file |*.jpg |bmp file |*.bmp"
If ofd.ShowDialog = DialogResult.OK Then
bmp.Save(ofd.FileName)
End If
End Sub