VB NET屏幕截图方法2则

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

屏幕截图方法2则

' 根据VB6代码改的,经过本人优化。请先导入Drawing类库。DeclareFunction SelectObject Lib"gdi32" (ByVal hdc AsInteger,

ByVal hObject AsInteger) AsInteger

DeclareFunction BitBlt Lib"gdi32" (ByVal hDestDC AsInteger, ByVal x AsInteger, ByVal y AsInteger, ByVal nWidth AsInteger,

ByVal nHeight AsInteger, ByVal hSrcDC AsInteger, ByVal xSrc AsInteger, ByVal ySrc AsInteger, ByVal dwRop AsInteger) AsInteger DeclareFunction CreateCompatibleBitmap Lib"gdi32"(ByVal hdc AsInteger, ByVal nWidth AsInteger, ByVal nHeight AsInteger) AsInteger DeclareFunction CreateDC Lib"gdi32"Alias"CreateDCA"

(ByVal lpDriverName AsString, ByVal lpDeviceName AsString,

ByVal lpOutput AsString, ByRef lpInitData AsInteger) AsInteger DeclareFunction CreateCompatibleDC Lib"gdi32" (ByVal hdc AsInteger) AsInteger

Function GetSerPic(OptionalByVal BitWidth AsInteger = -1, OptionalByVal BitHeight AsInteger = -1) As Image

If BitWidth<0Then BitWidth = puter.Screen.Bounds.Width

If BitHeight<0Then BitHeight = puter.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就可以进行屏幕截取的代码。

PublicClass frmMain

PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Me.Hide()

Dim p1 AsNew Point(0, 0)

Dim p2 AsNew Point(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height)

Dim pic AsNew Bitmap(p2.X, p2.Y)

Using g As Graphics = Graphics.FromImage(pic)

g.CopyFromScreen(p1, p1, p2)

Me.BackgroundImage = pic

EndUsing

Me.Show() End Sub End Class

相关文档
最新文档