Пример #1
0
        private bool AddTextToGIF(List<string> listText, string pathFileGIF, string pathSaveFile)
        {
            Image originalImg = Image.FromFile(pathFileGIF);
            Image[] frames = getFrames(originalImg); //get array frame of GIF
            PropertyItem item = originalImg.GetPropertyItem(0x5100); // FrameDelay in libgdiplus
            int delay = (item.Value[0] + item.Value[1] * 256) * 10; // Time is in 1/100ths of a second
                                                                    //decode GIF

            for (int i = 0; i < listText.Count; i++)
            {
                AnimatedGifEncoder e = new AnimatedGifEncoder();
                e.Start(pathSaveFile);
                e.SetDelay(delay);
                pathSaveFile = pathSaveFile + "\\aaaaa"+i+".gif";
                e.SetRepeat(0);
                for (int j = 0; j < frames.Length; j++)
                {
                    Image temp = frames[j];
                    Graphics graphics = Graphics.FromImage(temp);
                    graphics.DrawString(listText[i], this.Font, Brushes.Red, 0, 0);
                    e.AddFrame(temp);
                }
                e.Finish();

            }

            return true;
        }
Пример #2
0
 private void Demo()
 {
     /* 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);
     }
 }