C#获取gif帧数

C#获取gif帧数

        /// <summary>
        /// 获取gif帧数
        /// </summary>
        /// <param name="gifBytes"></param>
        /// <returns></returns>
        public static int GetGifFrameNum(string etc, byte[] gifBytes)
        {
            try
            {
                if (etc == ".gif")
                {
                    MemoryStream ms = new MemoryStream(gifBytes);
                    Image gif = Image.FromStream(ms);
                    FrameDimension fd = new FrameDimension(gif.FrameDimensionsList[0]);
                    int count = gif.GetFrameCount(fd);
                    ms.Dispose();
                    gif.Dispose();
                    return count;
                }
                else
                {
                    return 1;
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(ex);
                return 0;
            }
        }

  

posted @ 2018-10-18 16:27  小何同學  阅读(1181)  评论(0编辑  收藏  举报