zoukankan      html  css  js  c++  java
  • C# 截屏

        /// <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>
            public static string 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);
    
                    return string.Empty;
                }
                
            }
    
            /// <summary>
            /// 截图
            /// </summary>
            /// <param name="fileName">文件名,不包含后缀名</param>
            public static string Screenshot(string fileName)
            {
                return Screenshot(fileName, _filePath);
            }
            #endregion
            
        }
  • 相关阅读:
    images have the “stationarity” property, which implies that features that are useful in one region are also likely to be useful for other regions.
    算法报告
    word2vec_basic.py
    Softmax_function
    Convex combination
    函数的光滑化或正则化 卷积 应用 两个统计独立变量X与Y的和的概率密度函数是X与Y的概率密度函数的卷积
    world embedding 嵌入
    dump json 显示中文问题
    dump json 显示中文问题
    perl $d = encode_utf8($r); $f = decode_json($d)
  • 原文地址:https://www.cnblogs.com/xiaoyu369/p/4159652.html
Copyright © 2011-2022 走看看