示例#1
0
        public void Empty()
        {
            FrameDimension fd = new FrameDimension(Guid.Empty);

            Assert.AreEqual("00000000-0000-0000-0000-000000000000", fd.Guid.ToString(), "Guid");
            Assert.AreEqual(Guid.Empty.GetHashCode(), fd.GetHashCode(), "GetHashCode");
            Assert.AreEqual("[FrameDimension: 00000000-0000-0000-0000-000000000000]", fd.ToString(), "ToString");

            Assert.IsTrue(fd.Equals(new FrameDimension(Guid.Empty)), "Equals(Empty)");
            Assert.IsFalse(fd.Equals(null), "Equals(null)");
        }
示例#2
0
        /// <summary>
        ///    Whether or not the image has multiple time-based frames.
        /// </summary>
        public static bool CanAnimate(Image?image)
        {
            if (image == null)
            {
                return(false);
            }

            // See comment in the class header about locking the image ref.
#pragma warning disable CA2002
            lock (image)
            {
#pragma warning restore CA2002
                Guid[] dimensions = image.FrameDimensionsList;

                foreach (Guid guid in dimensions)
                {
                    FrameDimension dimension = new FrameDimension(guid);
                    if (dimension.Equals(FrameDimension.Time))
                    {
                        return(image.GetFrameCount(FrameDimension.Time) > 1);
                    }
                }
            }

            return(false);
        }
示例#3
0
        public void Equals()
        {
            FrameDimension fd = new FrameDimension(new Guid("7462dc86-6180-4c7e-8e3f-ee7333a7a483"));

            // equals
            Assert.IsTrue(fd.Equals(FrameDimension.Page), "Page");
            // but ToString differs!
            Assert.AreEqual("[FrameDimension: 7462dc86-6180-4c7e-8e3f-ee7333a7a483]", fd.ToString(), "ToString");
        }
示例#4
0
        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;
                            }
                        }
                    }
                    catch (Exception) {
                        // ignore any exceptions...
                        //
                    }
                }
            }
        }
        // image lock should be held
        //
        private bool ImageHasTimeFrames(Image image)
        {
            foreach (Guid guid in image.FrameDimensionsList)
            {
                FrameDimension dimension = new FrameDimension(guid);
                if (dimension.Equals(FrameDimension.Time))
                {
                    return(image.GetFrameCount(FrameDimension.Time) > 1);
                }
            }

            return(false);
        }
 /// <include file='doc\ImageAnimator.uex' path='docs/doc[@for="ImageAnimator.CanAnimate"]/*' />
 /// <devdoc>
 ///    Whether or not the image has multiple frames.
 /// </devdoc>
 public static bool CanAnimate(Image image)
 {
     Guid[] dimensions = image.FrameDimensionsList;
     foreach (Guid guid in dimensions)
     {
         FrameDimension dimension = new FrameDimension(guid);
         if (dimension.Equals(FrameDimension.Time))
         {
             return(image.GetFrameCount(FrameDimension.Time) > 1);
         }
     }
     return(false);
 }
 public static bool CanAnimate(Image image)
 {
     if (image != null)
     {
         lock (image)
         {
             foreach (Guid guid in image.FrameDimensionsList)
             {
                 FrameDimension dimension = new FrameDimension(guid);
                 if (dimension.Equals(FrameDimension.Time))
                 {
                     return(image.GetFrameCount(FrameDimension.Time) > 1);
                 }
             }
         }
     }
     return(false);
 }
示例#8
0
        /// <summary>
        ///    Whether or not the image has multiple time-based frames.
        /// </summary>
        public static bool CanAnimate([NotNullWhen(true)] Image?image)
        {
            if (image == null)
            {
                return(false);
            }

            // See comment in the class header about locking the image ref.
            lock (image)
            {
                Guid[] dimensions = image.FrameDimensionsList;

                foreach (Guid guid in dimensions)
                {
                    FrameDimension dimension = new FrameDimension(guid);
                    if (dimension.Equals(FrameDimension.Time))
                    {
                        return(image.GetFrameCount(FrameDimension.Time) > 1);
                    }
                }
            }

            return(false);
        }
示例#9
0
文件: Image.cs 项目: nhbcyz/corefx
        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)
                    {
                    }
                }
            }
        }
示例#10
0
 public void Equals_Object_ReturnsExpected(FrameDimension frameDimension, object obj, bool result)
 {
     Assert.Equal(result, frameDimension.Equals(obj));
 }
 internal static void EnsureSave(Image image, string filename, Stream dataStream)
 {
     if (image.RawFormat.Equals(ImageFormat.Gif))
     {
         bool flag = false;
         foreach (Guid guid in image.FrameDimensionsList)
         {
             FrameDimension dimension = new FrameDimension(guid);
             if (dimension.Equals(FrameDimension.Time))
             {
                 flag = image.GetFrameCount(FrameDimension.Time) > 1;
                 break;
             }
         }
         if (flag)
         {
             try
             {
                 Stream stream   = null;
                 long   position = 0L;
                 if (dataStream != null)
                 {
                     position            = dataStream.Position;
                     dataStream.Position = 0L;
                 }
                 try
                 {
                     if (dataStream == null)
                     {
                         stream = dataStream = File.OpenRead(filename);
                     }
                     image.rawData = new byte[(int)dataStream.Length];
                     dataStream.Read(image.rawData, 0, (int)dataStream.Length);
                 }
                 finally
                 {
                     if (stream != null)
                     {
                         stream.Close();
                     }
                     else
                     {
                         dataStream.Position = position;
                     }
                 }
             }
             catch (UnauthorizedAccessException)
             {
             }
             catch (DirectoryNotFoundException)
             {
             }
             catch (IOException)
             {
             }
             catch (NotSupportedException)
             {
             }
             catch (ObjectDisposedException)
             {
             }
             catch (ArgumentException)
             {
             }
         }
     }
 }