using System; using System.Collections.Generic; using System.Text; using System.IO; using System.Windows.Forms; using System.Drawing; using System.Drawing.Imaging; using System.Threading; using OpenNETCF.Drawing; using System.Reflection; namespace SaveScreen { public class ScreenToImage { private static string systemPath = string.Empty; public static void SaveImage() { if (string.IsNullOrEmpty(systemPath)) { systemPath = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase.ToString()); } Thread t1 = new Thread(DoSaveImage); t1.Name = "保存截图"; t1.Start(); } private static void DoSaveImage() { try { Image image = new Bitmap(480, 635); Graphics g = Graphics.FromImage(image); GraphicsEx gex = GraphicsEx.FromGraphics(g); gex.CopyFromScreen(0, 0, 0, 0, new Size(480, 635)); DateTime dt = DateTime.Now; string fileName = dt.ToShortDateString() + dt.Hour.ToString("00") + dt.Minute.ToString("00") + dt.Second.ToString("00") + ".bmp"; fileName = System.IO.Path.Combine(systemPath, fileName); image.Save(fileName, ImageFormat.Bmp); gex.Dispose(); g.Dispose(); } catch (Exception ex) { MessageBox.Show("保存出错:" + ex.StackTrace.ToString()); } } } }