Click here to Skip to main content
14,690,616 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can I make automatic scheduled screen capture of the desktop and then automatic save it on a directory or send it via sftp?

1 solution

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

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900