【搬运】VB.NET屏幕截图方法2则

vb.net

 
  
' 根据VB6代码改的,经过本人优化。请先导入Drawing类库。

Declare Function SelectObject Lib " gdi32 " ( ByVal hdc As Integer , ByVal hObject As Integer ) As Integer
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
Declare Function CreateCompatibleBitmap Lib " gdi32 " ( ByVal hdc As Integer , ByVal nWidth As Integer , ByVal nHeight As Integer ) As Integer
Declare Function CreateDC Lib " gdi32 " Alias " CreateDCA " ( ByVal lpDriverName As String , ByVal lpDeviceName As String , ByVal lpOutput As String , ByRef lpInitData As Integer ) As Integer
Declare Function CreateCompatibleDC Lib " gdi32 " ( ByVal hdc As Integer ) As Integer

Function GetSerPic( Optional ByVal BitWidth As Integer = - 1 , Optional ByVal BitHeight As Integer = - 1 ) As Image
If BitWidth < 0 Then BitWidth = My.Computer.Screen.Bounds.Width
If BitHeight < 0 Then BitHeight = My.Computer.Screen.Bounds.Height
Dim Bhandle, DestDC, SourceDC As IntPtr
SourceDC
= CreateDC( " DISPLAY " , Nothing , Nothing , 0 )
DestDC
= CreateCompatibleDC(SourceDC)
Bhandle
= CreateCompatibleBitmap(SourceDC, BitWidth, BitHeight)
SelectObject(DestDC, Bhandle)
BitBlt(DestDC,
0 , 0 , BitWidth, BitHeight, SourceDC, 0 , 0 , & HCC0020)
Return Image.FromHbitmap(Bhandle)
End Function

 

 
  
' 最近学了Graphics类的画图方法,所以无聊就写了两个小程序。
'
这一例是不使用系统API就可以进行屏幕截取的代码。

Public Class frmMain

Private Sub Button1_Click( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me .Hide()
Dim p1 As New Point( 0 , 0 )
Dim p2 As New Point(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height)
Dim pic As New Bitmap(p2.X, p2.Y)
Using g As Graphics = Graphics.FromImage(pic)
g.CopyFromScreen(p1, p1, p2)
Me .BackgroundImage = pic
End Using
Me .Show()
End Sub

End Class

 

转载于:https://www.cnblogs.com/clso/archive/2010/11/29/1891104.html

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值