C# 截屏
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了C# 截屏,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1814字,纯文字阅读大概需要3分钟。
内容图文
![C# 截屏](/upload/InfoBanner/zyjiaocheng/1212/c0c506188c67413a8def55ee07a9aa97.jpg)
/// <summary> /// 辅助类 /// </summary> public class ScreenHelper { // 文件保存 private static string _filePath = string.Empty; #region 构造函数 ///<summary>/// 私有构造函数 ///</summary>private ScreenHelper() { } ///<summary>/// 静态构造函数 ///</summary>static ScreenHelper() { _filePath = System.Environment.CurrentDirectory; string filePath = System.Configuration.ConfigurationManager.AppSettings["ScreenshotFilePath"]; if (!string.IsNullOrEmpty(filePath)) { _filePath = filePath; } } ///<summary>/// 截图 ///</summary>///<param name="fileName">文件名,不包含后缀</param>///<param name="filePath">文件路径</param>publicstaticstring Screenshot(string fileName,string filePath) { try { string dtString = DateTime.Now.ToString("yyyy-MM-dd"); string dir = filePath + "\\Screenshot\\" + dtString + "\\"; //判断文件夹是否存在,不存在则创建if (System.IO.Directory.Exists(dir) == false) { System.IO.Directory.CreateDirectory(dir); } string fullPath = dir + fileName + "_" + Guid.NewGuid().ToString() + ".jpg"; //获得当前屏幕的分辨率 Screen scr = Screen.PrimaryScreen; Rectangle rc = scr.Bounds; int iWidth = rc.Width; int iHeight = rc.Height; //创建一个和屏幕一样大的Bitmap Image myImage = new Bitmap(iWidth, iHeight); //从一个继承自Image类的对象中创建Graphics对象 Graphics g = Graphics.FromImage(myImage); //抓屏并拷贝到myimage里 g.CopyFromScreen(new Point(0, 0), new Point(0, 0), new Size(iWidth, iHeight)); //保存为文件 myImage.Save(fullPath); return fullPath; } catch (Exception ex) { Com.LogHelper.WriteLog(ex.Message, ex.StackTrace, Com.LogType.OtherError); returnstring.Empty; } } ///<summary>/// 截图 ///</summary>///<param name="fileName">文件名,不包含后缀名</param>publicstaticstring Screenshot(string fileName) { return Screenshot(fileName, _filePath); } #endregion }
原文:http://www.cnblogs.com/xiaoyu369/p/4159652.html
内容总结
以上是互联网集市为您收集整理的C# 截屏全部内容,希望文章能够帮你解决C# 截屏所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。