public static bool CanAnimate(Image image) { if (image == null) { return(false); } int n = image.FrameDimensionsList.Length; if (n < 1) { return(false); } for (int i = 0; i < n; i++) { if (image.FrameDimensionsList [i].Equals(FrameDimension.Time.Guid)) { return(image.GetFrameCount(FrameDimension.Time) > 1); } } return(false); }
public AnimateEventArgs(Image image) { frameCount = image.GetFrameCount(FrameDimension.Time); }
/// <summary> /// 验证保存 TODO 2019-08 /// </summary> /// <param name="image"></param> /// <param name="filename"></param> /// <param name="dataStream"></param> internal static void EnsureSave(Image image, string filename, Stream dataStream) { if (image.RawFormat.Equals(ImageFormat.Gif)) { bool animatedGif = false; Guid[] dimensions = image.FrameDimensionsList; foreach (Guid guid in dimensions) { FrameDimension dimension = new FrameDimension(guid); if (dimension.Equals(FrameDimension.Time)) { animatedGif = image.GetFrameCount(FrameDimension.Time) > 1; break; } } if (animatedGif) { try { Stream created = null; long lastPos = 0; if (dataStream != null) { lastPos = dataStream.Position; dataStream.Position = 0; } try { if (dataStream == null) { created = dataStream = File.OpenRead(filename); } image.rawData = new byte[(int)dataStream.Length]; dataStream.Read(image.rawData, 0, (int)dataStream.Length); } finally { if (created != null) { created.Close(); } else { dataStream.Position = lastPos; } } } // possible exceptions for reading the filename catch (UnauthorizedAccessException) { } catch (DirectoryNotFoundException) { } catch (IOException) { } // possible exceptions for setting/getting the position inside dataStream catch (NotSupportedException) { } catch (ObjectDisposedException) { } // possible exception when reading stuff into dataStream catch (ArgumentException) { } } } }