Thursday, July 2, 2009

Coding for Creating a Window Snap Shot Using C#.net

Add the reference of system.windows.form by address reference option 

using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;

//file name is created based on a time
File_name.Text = System.DateTime.Now.ToShortTimeString();
  string file_name = File_name.Text.Replace(':', '-');
  Bitmap image = new Bitmap(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
  System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(image);  graphics.CopyFromScreen(System.Windows.Forms.Screen.PrimaryScreen.Bounds.X, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Y, 0, 0, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Size, System.Drawing.CopyPixelOperation.SourceCopy);
 image.Save("C:/temp/" + file_name.ToString()+".jpg");
Note:
IF You want to take a snap shot for particualr timer interval, just added a meta tag inside head tag
meta http-equiv="refresh" content="60"
60 refers the page refreshing time in a seconds..

No comments: