C#获取gif帧数

时间:2023-03-10 02:22:10
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;
}
}