Exemple #1
0
        /// <summary>
        /// 获取视频的宽高
        /// </summary>
        /// <param name="urlOrPath"></param>
        /// <returns></returns>
        public static (int, int) GetVideoWH(string filePath)
        {
            var w_h = (0, 0);

            if (string.IsNullOrEmpty(filePath))
            {
                return(w_h);
            }
            if (!File.Exists(filePath))
            {
                return(w_h);
            }

            try
            {
                w_h = ServiceIniWhHelper.ReadVideo(filePath);
                if (w_h.Item2 <= 0)
                {
                    w_h = FFPobeHelper.GetVideoInfo(filePath);
                    ServiceIniWhHelper.WriteVideo(filePath, w_h.Item1, w_h.Item2);
                }
                return(w_h);
            }
            catch
            {
                return(w_h);
            }
        }
Exemple #2
0
        /// <summary>
        /// 获取图片宽高
        /// </summary>
        /// <param name="urlOrPath"></param>
        public static (int, int) GetImageWH(string urlOrPath)
        {
            var w_h = (0, 0);

            if (string.IsNullOrEmpty(urlOrPath))
            {
                return(w_h);
            }

            try
            {
                w_h = ServiceIniWhHelper.ReadImage(urlOrPath);
                if (w_h.Item2 == 0)
                {
                    #region 网络图片
                    if (urlOrPath.StartsWith("http"))
                    {
                        var client     = new WebClient();
                        var stream     = client.OpenReadTaskAsync(urlOrPath).Result;
                        var networkImg = Image.FromStream(stream);
                        w_h = (networkImg.Width, networkImg.Height);
                    }
                    #endregion

                    #region 本地图片
                    else
                    {
                        var localImg = Image.FromFile(urlOrPath);
                        w_h = (localImg.Width, localImg.Height);
                    }
                    #endregion
                }

                ServiceIniWhHelper.WriteImage(urlOrPath, w_h.Item1, w_h.Item2);
                return(w_h);
            }
            catch
            {
                return(w_h);
            }
        }