使用纯net技术实现抓屏(包含连续抓图和鼠标的问题的解决方法)
之前转载了一篇关于api抓屏的实例,本次载的是老外Jason Hensley写的抓屏,实现方式与上次不同,可以方便大家对比 ''开发平台 VB.NET 2005 <Beta 2> ''Description: A basic example of using the new built-in Sub in the ''Update: Reworked the code to be compatible for VB.NET <Beta 2>. I Private Sub btnCopy_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles btnCopy.Click 'Create the bitmap and graphics objects. Dim s As Size = New Size(Screen.PrimaryScreen.WorkingArea.Width,Screen.PrimaryScreen.WorkingArea.Height) 'See whether or not to hide the program before taking the Me.Hide() 'Clear this variable from memory. Else 'Copy the image from the screen. You can customize the size End If 'Load the copied image to the picturebox control. 'Clean up alittle. End Sub Private Sub btnSave_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles btnSave.Click Dim saveDlg As SaveFileDialog = New SaveFileDialog 'Set the filter to JPEG files only. dlgResult = saveDlg.ShowDialog If dlgResult = Windows.Forms.DialogResult.OK Then 'Save the image contained in the picturebox. End If End Sub End Class
我的补充: 1)如果想连续抓屏,就必须将下面的定义部分改为全局变量,以防止反复定义新对象而导致系统崩溃 Dim b As Bitmap= New Bitmap(Screen.PrimaryScreen.WorkingArea.Width,Screen.PrimaryScreen.WorkingArea.Height) Dim s As Size = New Size(Screen.PrimaryScreen.WorkingArea.Width,Screen.PrimaryScreen.WorkingArea.Height) 2)抓鼠标的问题,必须获取鼠标位置,然后绘制鼠标到图像
g.CopyFromScreen(SecScreen_x,SecScreen_y,d_x,d_y,Copy_size,CopyPixelOperation.SourceCopy) '添加鼠标位置 Cursor.Current.Draw(g,New Rectangle(Cursor.Position,Cursor.Current.Size))
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |