Mega Code Archive

 
Categories / C# / 2D Graphics
 

Takes a screen shot saves it to the specified directory and returns the full file path

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; using System.Drawing; using System.IO; using System.Runtime.Serialization.Formatters.Binary; namespace AltSerializer.Tests {     public static class Common     {         /// <summary>         /// Takes a screen shot saves it to the specified directory and returns the full file path         /// </summary>         /// <param name="sPath"></param>         /// <returns></returns>         public static string ScreenShot(string path, string fileName)         {             path = System.IO.Path.Combine(path, fileName);             try             {                 SendKeys.SendWait("{PRTSC 2}");                 IDataObject data = Clipboard.GetDataObject();                 if (data.GetDataPresent(typeof(System.Drawing.Bitmap)))                 {                     Image img = (System.Drawing.Bitmap)data.GetData(typeof(System.Drawing.Bitmap));                     img.Save(path);                 }             }             catch             { }             return path;         }     } }