I am creating an app that takes a screenshot of the desktop at a certain interval of time.
Code:
String nme = "";
Bitmap printscreen = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
Screen.PrimaryScreen.Bounds.Height);
Graphics graphics = Graphics.FromImage(printscreen as Image);
graphics.CopyFromScreen(0, 0, 0, 0, printscreen.Size);
nme = DateTime.Now.ToString();
printscreen.Save(@"F:\Temp\printScre.jpg", ImageFormat.Jpeg);
- Is CopyFromScreen a right way to get the screenshot of the desktop?
- If I want to send this screenshot to the remote server, then what should be the best way to do that?
- Should I do some compression before sending it, and if so what are the most efficient ways?
Yes, it is a perfectly right way. Although, I recommed you to visit the following links here on SO, because there are already answers to your question in some form.
Another solution with CopyFromScreen and more complicated solution with some insight on the problem.
As for sending to a remote server, consider using
TcpClient
or email. Compression is always a good idea if you take more screens or if network is slow, dics space is low, etc. Regarding compression efficiency, look at some archivators available out there and take what you need. They vary mainly in a compression format, speed and compression quality, but you can almost with all of them decide if you need speed or quality.Code snippet for sending email with attachment:
(based on this blog)
Code snippet for FTP:
(based on MSDN)