【搬运】VB.NET屏幕截图方法2则
' 根据VB6代码改的,经过本人优化。请先导入Drawing类库。
Declare Function SelectObject Lib " gdi32 " ( ByVal hdc As Integer , hObject ) BitBlt hDestDC x y nWidth nHeight hSrcDC xSrc ySrc dwRop CreateCompatibleBitmap CreateDC Alias CreateDCA lpDriverName String lpDeviceName lpOutput ByRef lpInitData CreateCompatibleDC
GetSerPic( Optional BitWidth = - 1 BitHeight Image
If < 0 Then My.Computer.Screen.Bounds.Width
My.Computer.Screen.Bounds.Height
Dim Bhandle,DestDC,SourceDC IntPtr
SourceDC CreateDC( DISPLAY Nothing )
DestDC CreateCompatibleDC(SourceDC)
Bhandle CreateCompatibleBitmap(SourceDC,BitWidth,BitHeight)
SelectObject(DestDC,Bhandle)
BitBlt(DestDC,BitHeight,SourceDC,0); font-family:'Courier New'!important; line-height:1.5!important">& HCC0020)
Return Image.FromHbitmap(Bhandle)
End Function
最近学了Graphics类的画图方法,所以无聊就写了两个小程序。
'
这一例是不使用系统API就可以进行屏幕截取的代码。
Public
Class
frmMain
Private Sub Button1_Click( sender System.Object,0); font-family:'Courier New'!important; line-height:1.5!important"> e System.EventArgs) Handles Button1.Click
Me .Hide()
p1 New Point( p2 Point(Screen.PrimaryScreen.Bounds.Width,Screen.PrimaryScreen.Bounds.Height)
pic Bitmap(p2.X,p2.Y)
Using g Graphics Graphics.FromImage(pic)
g.CopyFromScreen(p1,p1,p2)
.BackgroundImage pic
End .Show()
End Sub End Class
Private Sub Button1_Click( sender System.Object,0); font-family:'Courier New'!important; line-height:1.5!important"> e System.EventArgs) Handles Button1.Click
Me .Hide()
p1 New Point( p2 Point(Screen.PrimaryScreen.Bounds.Width,Screen.PrimaryScreen.Bounds.Height)
pic Bitmap(p2.X,p2.Y)
Using g Graphics Graphics.FromImage(pic)
g.CopyFromScreen(p1,p1,p2)
.BackgroundImage pic
End .Show()
End Sub End Class