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);
Yes, it is a perfectly right way. Although, I recommend 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:
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient(YOUR SMTP SERVER ADDRESS);
mail.From = new MailAddress(SENDER ADDRESS);
mail.To.Add(RECEIVER ADDRESS);
mail.Subject = "Test Mail - 1";
mail.Body = "mail with attachment";
System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment("YOURFILE");
mail.Attachments.Add(attachment);
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential(YOUR_SMTP_USER_NAME, YOUR_SMTP_PASSWORD);
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
(based on this blog)
Code snippet for FTP:
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://www.contoso.com/test.htm");
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential ("anonymous","[email protected]");
StreamReader sourceStream = new StreamReader("testfile.txt");
byte [] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
sourceStream.Close();
request.ContentLength = fileContents.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(fileContents, 0, fileContents.Length);
requestStream.Close();
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);
response.Close();
(based on MSDN)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With