using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Drawing; using System.IO; using System.Windows.Forms; namespace Test { public static class ScreenShotSupport { public static void AddComment(string savePath, string fileName, string comment) { string path = savePath + "//" + fileName + ".txt"; if (!Directory.Exists(savePath)) { Directory.CreateDirectory(savePath); } if (!File.Exists(path)) { FileStream fs = File.Create(path); using (fs) { using (StreamWriter sw = new StreamWriter(fs)) { sw.Write(comment); } } } else { FileStream fs = File.Open(path, FileMode.Open); using (fs) { using (StreamWriter sw = new StreamWriter(fs)) { sw.Write(comment); } } } } public static void CaptureScreenshot(string savepath, string fileName, string comment) { if (!Directory.Exists(savepath)) Directory.CreateDirectory(savepath); string filePath = Path.Combine(savepath, fileName); if (File.Exists(filePath)) { FileInfo fileInfo = new FileInfo(filePath); if (fileInfo.IsReadOnly) { fileInfo.Attributes = FileAttributes.Normal; } File.Delete(filePath); } Rectangle fullScreenRect = SystemInformation.VirtualScreen; Bitmap bitmap = new Bitmap(fullScreenRect.Width, fullScreenRect.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); using (Graphics graphOrignal = Graphics.FromImage(bitmap)) { graphOrignal.CopyFromScreen(new Point(0, 0), new Point(0, 0), fullScreenRect.Size); } Bitmap newbitmap = new Bitmap(fullScreenRect.Width, fullScreenRect.Height + 100, System.Drawing.Imaging.PixelFormat.Format32bppArgb); using (Graphics graphExpect = Graphics.FromImage(newbitmap)) { Font font = new Font("Arial", 12, FontStyle.Bold); SolidBrush brush = new SolidBrush(Color.Red); graphExpect.Clear(Color.White); graphExpect.DrawImage(bitmap, 0, 0, new Rectangle(0, 0, bitmap.Width, bitmap.Height), GraphicsUnit.Pixel); graphExpect.DrawString(comment, font, brush, new Rectangle(0, bitmap.Height, bitmap.Width, 100)); font.Dispose(); brush.Dispose(); } newbitmap.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg); } public static void CaptureScreenshot(string fileName, string comment) { string savepath = AppDomain.CurrentDomain.BaseDirectory; CaptureScreenshot(savepath, fileName, comment); } } }