自动屏幕捕获 [英] automatic screen capture

查看:92
本文介绍了自动屏幕捕获的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何自动对桌面进行定时的屏幕截图,然后自动将其保存在目录中或通过sftp发送?

How can I make automatic scheduled screen capture of the desktop and then automatic save it on a directory or send it via sftp?

推荐答案

<pre lang="vb">Private Sub PerformCapture()<br />
'' turn the form invisible so you don''t show it during capture<br />
Me.Visible = False<br />
''use the GDI call and create a DC to the whole display<br />
Dim dc1 As IntPtr = CreateDC("DISPLAY", Nothing, Nothing, CType(Nothing, IntPtr))<br />
''create a Graphics object for the screen dc<br />
Dim g1 As Graphics = Graphics.FromHdc(dc1)<br />
'' create a compatible bitmap the size of the entire screen<br />
MyImage = New Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, g1)<br />
'' use the bitmap to create another Graphics surface so we can BitBlast into the bitmap<br />
Dim g2 As Graphics = Graphics.FromImage(MyImage)<br />
'' Now go retrace our steps and get the device contexts for both the bitmap and the screen<br />
'' Note: Apparently you have to do this, and can''t go directly from the aquired dc or exceptions are thrown<br />
'' When you try to release the dcs<br />
dc1 = g1.GetHdc()<br />
Dim dc2 As IntPtr = g2.GetHdc()<br />
'' Bit Blast the screen into the Bitmap<br />
BitBlt(dc2, 0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, dc1, 0, 0, 13369376)<br />
'' Remember to release the dc''s, otherwise problems down the road<br />
g1.ReleaseHdc(dc1)<br />
g2.ReleaseHdc(dc2)<br />
'' Save the image to JPEG file<br />
MyImage.Save("c:\Captured.jpg", ImageFormat.Jpeg)<br />
'' Now we can view our form again, so make it visible<br />
Visible = True<br />
MessageBox.Show("Finished Saving Image")<br />
'' Set the Bounds of the form so that it fills the entire screen<br />
'' Because in our Paint event handler we are going to draw the bitmap to the form<br />
Me.SetBounds(0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height)<br />
'' ************** Set up functions for doing additional bitmap manipulation such as cropping a portion of<br />
'' ************* the image ****************(Not required for screen capture)SetupCropping()<br />
firstCrop = True<br />
End Sub</pre><br />


要将图像上传到sftp,请点击此链接
sharpSsh-用于.NET的安全Shell(SSH)库 [


to upload image to sftp follow this link
sharpSsh - A Secure Shell (SSH) library for .NET[^]


这篇关于自动屏幕捕获的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆