コード例 #1
0
 public void ProfileTest()
 {
     ReportStart();
     _encoder = new AnimatedGifEncoder();
     _encoder.AddFrame(new GifFrame(RandomBitmap.Create(new Size(500, 500),
                                                        10,
                                                        PixelFormat.Format32bppArgb)));
     System.Threading.Thread t
                    = new System.Threading.Thread(EncodeBigFile);
     t.IsBackground = true;
     t.Start();
     while (t.IsAlive)
     {
         foreach (ProgressCounter counter in _encoder.AllProgressCounters.Values)
         {
             WriteMessage(counter.ToString());
         }
         System.Threading.Thread.Sleep(100);
     }
     ReportEnd();
 }
コード例 #2
0
        private void TryDifferentPixelFormats()
        {
            Size size       = new Size(50, 50);
            int  blockiness = 10;

            PixelFormat[] pixelFormats = new PixelFormat[]
            {
                PixelFormat.Format16bppArgb1555,
                PixelFormat.Format16bppRgb555,
                PixelFormat.Format16bppRgb565,
                PixelFormat.Format24bppRgb,
                PixelFormat.Format32bppArgb,
                PixelFormat.Format32bppPArgb,
                PixelFormat.Format32bppRgb,
                PixelFormat.Format48bppRgb,
                PixelFormat.Format64bppArgb,
                PixelFormat.Format64bppPArgb,
            };
            foreach (PixelFormat pf in pixelFormats)
            {
                string formatName = pf.ToString();

                _encoder = new AnimatedGifEncoder();
                for (int i = 0; i < 10; i++)
                {
                    Bitmap bitmap = RandomBitmap.Create(size,
                                                        blockiness,
                                                        pf);
                    _encoder.AddFrame(new GifFrame(bitmap));
                }

                DateTime startTime = DateTime.Now;
                _encoder.WriteToFile(formatName + ".gif");
                DateTime endTime          = DateTime.Now;
                TimeSpan timeToEncode8bit = endTime - startTime;
                WriteMessage("Encoding " + formatName + " took " + timeToEncode8bit);
            }
        }
コード例 #3
0
        public void Bug2892015()
        {
            ReportStart();
            _e = new AnimatedGifEncoder();

            #region create 10 random bitmaps
            Collection <Bitmap> bitmaps = new Collection <Bitmap>();
            for (int i = 0; i < 10; i++)
            {
                Bitmap bitmap = RandomBitmap.Create(new Size(50, 50),
                                                    10,
                                                    PixelFormat.Format32bppRgb);
                bitmaps.Add(bitmap);
            }
            #endregion

            DateTime startTime;
            DateTime endTime;

            #region create animation using just the first 3 (this should be quick)
            for (int i = 0; i < 3; i++)
            {
                _e.AddFrame(new GifFrame(bitmaps[i]));
            }

            startTime = DateTime.Now;
            _e.WriteToFile("2892015-1.gif");
            endTime = DateTime.Now;
            TimeSpan runTime1 = endTime - startTime;
            WriteMessage("Encoding 3 frames took " + runTime1);
            #endregion

            _e.Frames.Clear();

            #region create animation using all the bitmaps (this will take longer)
            foreach (Bitmap bitmap in bitmaps)
            {
                _e.AddFrame(new GifFrame(bitmap));
            }

            startTime = DateTime.Now;
            _e.WriteToFile("2892015-2.gif");
            endTime = DateTime.Now;
            TimeSpan runTime2 = endTime - startTime;
            WriteMessage("Encoding all " + bitmaps.Count + " frames took " + runTime2);
            #endregion

            _e.Frames.Clear();

            #region create animation using just the first 3 (this should be quick)
            for (int i = 0; i < 3; i++)
            {
                _e.AddFrame(new GifFrame(bitmaps[i]));
            }

            startTime = DateTime.Now;
            _e.WriteToFile("2892015-3.gif");
            endTime = DateTime.Now;
            TimeSpan runTime3 = endTime - startTime;
            WriteMessage("Encoding 3 frames took " + runTime3);
            #endregion

            Assert.IsTrue(runTime3 < runTime2);
            _d = new GifDecoder("2892015-3.gif");
            _d.Decode();
            Assert.AreEqual(3, _d.Frames.Count);

            ReportEnd();
        }