Exemple #1
0
        public void TestLoadGIF89a()
        {
            GifDecoder a_decoder = new GifDecoder();
            Stream sm = Assembly.GetExecutingAssembly().GetManifestResourceStream("SnCore.Tools.Tests.Images.animated.gif");
            Console.WriteLine("Bytes: {0}", sm.Length);
            a_decoder.Read(sm);
            Console.WriteLine("Frames: {0}", a_decoder.GetFrameCount());

            sm.Seek(0, SeekOrigin.Begin);
            Assert.IsNotNull(sm);
            ThumbnailBitmap b = new ThumbnailBitmap(sm);
            Console.WriteLine("Size: {0}x{1}", b.FullSize.Width, b.FullSize.Height);
            Assert.AreEqual(new Size(320, 240), b.FullSize);
            Assert.IsNotNull(b.Thumbnail);
            Assert.IsNotNull(b.Bitmap);
            ThumbnailBitmap th = new ThumbnailBitmap(b.Thumbnail);
            Console.WriteLine("Size: {0}x{1}", th.FullSize.Width, th.FullSize.Height);
            Assert.AreEqual(new Size(150, 100), th.FullSize);
            
            // make sure that the bitmap is still animated            
            Console.WriteLine("Bytes: {0}", b.Bitmap.Length);
            GifDecoder decoder = new GifDecoder();
            decoder.Read(new MemoryStream(b.Bitmap));
            Console.WriteLine("Frames: {0}", decoder.GetFrameCount());

            GifDecoder th_decoder = new GifDecoder();
            Console.WriteLine("Bytes: {0}", b.Thumbnail.Length);
            th_decoder.Read(new MemoryStream(b.Thumbnail));
            Console.WriteLine("Frames: {0}", th_decoder.GetFrameCount());
            Assert.AreEqual(th_decoder.GetFrameCount(), decoder.GetFrameCount());
        }
		static void Main(string[] args)
		{
			/* create Gif */
			//you should replace filepath
			String [] imageFilePaths = new String[]{"c:\\01.png","c:\\02.png","c:\\03.png"}; 
			String outputFilePath = "c:\\test.gif";
			AnimatedGifEncoder e = new AnimatedGifEncoder();
			e.Start( outputFilePath );
			e.SetDelay(500);
			//-1:no repeat,0:always repeat
			e.SetRepeat(0);
			for (int i = 0, count = imageFilePaths.Length; i < count; i++ ) 
			{
				e.AddFrame( Image.FromFile( imageFilePaths[i] ) );
			}
			e.Finish();
			/* extract Gif */
			string outputPath = "c:\\";
			GifDecoder gifDecoder = new GifDecoder();
			gifDecoder.Read( "c:\\test.gif" );
			for ( int i = 0, count = gifDecoder.GetFrameCount(); i < count; i++ ) 
			{
				Image frame = gifDecoder.GetFrame( i );  // frame i
				frame.Save( outputPath + Guid.NewGuid().ToString() + ".png", ImageFormat.Png );
			}
		}
Exemple #3
0
        public void ConsumeAnimatedGIFTest()
        {
            MemoryStream ms = new MemoryStream();
            AnimatedGifEncoder encoder = new AnimatedGifEncoder();
            // encoder.SetDelay(200);
            encoder.SetFrameRate(5);
            encoder.Start(ms);
            for (char i = 'a'; i <= 'z'; i++)
            {
                Console.Write(i.ToString());
                encoder.AddFrame(ThumbnailBitmap.GetBitmapFromText(i.ToString(), 48, 100, 200));
            }
            Console.WriteLine();
            encoder.Finish();
            ms.Flush();
            ms.Seek(0, SeekOrigin.Begin);

            GifDecoder decoder = new GifDecoder();
            decoder.Read(ms);
            Console.WriteLine("Frames: {0}", decoder.GetFrameCount());
            Assert.AreEqual(26, decoder.GetFrameCount());
        }
        public static void Resize(GifDecoder decoder, Stream outStream, int width, int height, int quality)
        {
            AnimatedGifEncoder encoder = new AnimatedGifEncoder();
            Size sourcesize            = decoder.GetFrameSize();

            encoder.SetSize(sourcesize.Width < sourcesize.Height ? new Size(width, height) : new Size(height, width));
            encoder.SetRepeat(decoder.GetLoopCount());
            // encoder.SetQuality(quality);
            encoder.Start(outStream);
            for (int i = 0; i < decoder.GetFrameCount(); i++)
            {
                GifDecoder.GifFrame frame = decoder.GetFrame(i);
                encoder.SetDelay(frame.delay);
                encoder.SetTransparent(Color.FromArgb(frame.bgcolor));
                encoder.AddFrame(decoder.GetFrameImage(i));
            }
            encoder.Finish();
            outStream.Flush();
        }
 private void button1_Click(object sender, EventArgs e)
 {
     String[] imageFilePaths = new String[] { "C:\\2.png", "C:\\3.png" };
     String outputFilePath = "C:\\ani.gif";
     AnimatedGifEncoder ec = new AnimatedGifEncoder();
     ec.Start(outputFilePath);
     ec.SetDelay(500);
     //-1:no repeat,0:always repeat
     ec.SetRepeat(0);
     for (int i = 0, count = imageFilePaths.Length; i < count; i++)
     {
         ec.AddFrame(Image.FromFile(imageFilePaths[i]));
     }
     ec.Finish();
     /* extract Gif */
     string outputPath = "c:\\";
     GifDecoder gifDecoder = new GifDecoder();
     gifDecoder.Read("c:\\test.gif");
     for (int i = 0, count = gifDecoder.GetFrameCount(); i < count; i++)
     {
         Image frame = gifDecoder.GetFrame(i);  // frame i
         frame.Save(outputPath + Guid.NewGuid().ToString() + ".png", System.Drawing.Imaging.ImageFormat.Png);
     }
 }
Exemple #6
0
        private static void GenerateThumbGif(GifDecoder decoder, string thumbPath, Size thumbSize)
        {
            GifEncoder encoder = new GifEncoder();

            encoder.Start(thumbPath);

            encoder.SetSize(thumbSize.Width, thumbSize.Height);

            encoder.SetRepeat(decoder.GetLoopCount());

            Bitmap bitmap = new Bitmap(thumbSize.Width, thumbSize.Height);

            for (int i = 0; i < decoder.GetFrameCount(); i++)
            {
                encoder.SetDelay(decoder.GetDelay(i));

                int dispose = decoder.GetDispose(i);

                Color tranColor = decoder.GetTransparent(i);

                if (tranColor.IsEmpty == false)
                    encoder.SetTransparent(decoder.GetTransparent(i));

                if (dispose != 1)
                {
                    bitmap.Dispose();
                    bitmap = new Bitmap(thumbSize.Width, thumbSize.Height);
                }

                using (Graphics g = Graphics.FromImage(bitmap))
                {
                    if (dispose == 2)
                    {
                        g.FillRectangle(new SolidBrush(tranColor), 0, 0, thumbSize.Width, thumbSize.Height);
                    }
                    //else if(dispose == 5)
                    //{
                    //    g.FillRectangle(new SolidBrush(Color.Black), 0, 0, thumbSize.Width, thumbSize.Height);
                    //}

                    g.DrawImage(decoder.GetFrame(i), 0, 0, thumbSize.Width, thumbSize.Height);
                }

                encoder.AddFrame(bitmap);
            }

            bitmap.Dispose();

            //using (Bitmap bitmap = new Bitmap(thumbSize.Width, thumbSize.Height))
            //{
            //    for (int i = 0; i < decoder.GetFrameCount(); i++)
            //    {
            //        encoder.SetDelay(decoder.GetDelay(i));

            //        Color tran = decoder.GetTransparent(i);

            //        using (Graphics g = Graphics.FromImage(bitmap))
            //        {
            //            if (tran != Color.Empty)
            //            {
            //                g.FillRectangle(new SolidBrush(tran), 0, 0, thumbSize.Width, thumbSize.Height);
            //            }
            //            else
            //            {

            //            }

            //            g.DrawImage(decoder.GetFrame(i), 0, 0, thumbSize.Width, thumbSize.Height);
            //        }

            //        encoder.AddFrame(bitmap);
            //    }
            //}

            encoder.Finish();
        }
Exemple #7
0
 public static void Resize(GifDecoder decoder, Stream outStream, int width, int height, int quality)
 {
     AnimatedGifEncoder encoder = new AnimatedGifEncoder();
     Size sourcesize = decoder.GetFrameSize();
     encoder.SetSize(sourcesize.Width < sourcesize.Height ? new Size(width, height) : new Size(height, width));
     encoder.SetRepeat(decoder.GetLoopCount());
     // encoder.SetQuality(quality);
     encoder.Start(outStream);
     for (int i = 0; i < decoder.GetFrameCount(); i++)
     {
         GifDecoder.GifFrame frame = decoder.GetFrame(i);
         encoder.SetDelay(frame.delay);
         encoder.SetTransparent(Color.FromArgb(frame.bgcolor));
         encoder.AddFrame(decoder.GetFrameImage(i));
     }
     encoder.Finish();
     outStream.Flush();
 }
        internal void DoInverseButterTransform_gif(string filepathToOpen, string filepathToSave, bool decrypt, string password = "")
        {
            GifDecoder gifDecoder = new GifDecoder();
            gifDecoder.Read(filepathToOpen);
            List<Bitmap> frames = new List<Bitmap>();
            for (int i = 0, count = gifDecoder.GetFrameCount(); i < count; i++)
            {
                frames.Add(new Bitmap(gifDecoder.GetFrame(i)));  // frame i

            }
            throw new NotImplementedException("Not yet implemented");

            byte[] payload = getPayloadFromImage(frames[1], decrypt, password);

            //saveBytesToFile(payload, filepathToSave);
        }