示例#1
0
文件: NGifTest.cs 项目: dblock/sncore
 public void CreateAnimatedGIFTest()
 {
     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));
     }
     encoder.Finish();
     Console.WriteLine();
 }
示例#2
0
文件: NGifTest.cs 项目: dblock/sncore
        public void ResizeAnimatedGIFTest()
        {
            string filename = Path.GetTempFileName();
            Console.WriteLine("Creating: {0}", filename);
            string resizedfilename = Path.GetTempFileName();
            Console.WriteLine("Resizing: {0}", resizedfilename);
            try
            {
                using (FileStream ms = File.OpenWrite(filename))
                {
                    AnimatedGifEncoder encoder = new AnimatedGifEncoder();
                    encoder.SetFrameRate(5);
                    encoder.Start(ms);
                    for (char i = 'a'; i <= 'e'; i++)
                    {
                        Console.Write(i.ToString());
                        encoder.AddFrame(ThumbnailBitmap.GetBitmapFromText(
                            i.ToString(), 48, 300, 200));
                    }
                    Console.WriteLine();
                    encoder.Finish();
                    ms.Flush();
                }

                using (FileStream ms = File.OpenRead(filename))
                {
                    using (FileStream resizedms = File.OpenWrite(resizedfilename))
                    {
                        AnimatedGifEncoder.Resize(ms, resizedms, 200, 150, 100);
                        resizedms.Flush();
                    }
                }
            }
            finally
            {
                if (File.Exists(filename))
                    File.Delete(filename);
                if (File.Exists(resizedfilename))
                    File.Delete(resizedfilename);
            }
        }
示例#3
0
文件: NGifTest.cs 项目: dblock/sncore
        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());
        }
示例#4
0
文件: NGifTest.cs 项目: dblock/sncore
        public void ResizeToThumbnailTest()
        {
            string filename = Path.GetTempFileName();
            Console.WriteLine("Creating: {0}", filename);
            try
            {
                MemoryStream ms = new MemoryStream();
                AnimatedGifEncoder encoder = new AnimatedGifEncoder();
                encoder.SetFrameRate(5);
                encoder.Start(ms);
                for (char i = 'a'; i <= 'e'; i++)
                {
                    Console.Write(i.ToString());
                    encoder.AddFrame(ThumbnailBitmap.GetBitmapFromText(
                        i.ToString(), 48, 300, 200));
                }
                Console.WriteLine();
                encoder.Finish();
                ms.Flush();
                ms.Seek(0, SeekOrigin.Begin);

                ThumbnailBitmap bitmap = new ThumbnailBitmap(ms);
                FileStream fs = File.Create(filename);
                byte[] th = bitmap.Thumbnail;
                fs.Write(th, 0, th.Length);
                fs.Close();
            }
            finally
            {
                if (File.Exists(filename))
                    File.Delete(filename);
            }
        }
示例#5
0
文件: Form1.cs 项目: reserad/Vid2Gif
        private string Conversion(string path, string VideoFileName)
        {
            List<string> FileNames = new List<string>();

            DirectoryInfo di = new DirectoryInfo(path);
            foreach (var fileName in di.GetFiles())
            {
                FileNames.Add(fileName.ToString());
            }
            string outputFilePath = path + VideoFileName + ".gif";
            AnimatedGifEncoder e = new AnimatedGifEncoder();
                e.Start(outputFilePath);
                e.SetFrameRate(15);
                e.SetQuality(1);
                //-1:no repeat,0:always repeat
                e.SetRepeat(0);
                for (int i = 0, count = FileNames.Count; i < count; i++)
                {
                    e.AddFrame(Image.FromFile(path + FileNames[i]));
                    pbEncoding.Value = Convert.ToInt32(100 * (double)i / (double)count);
                }
                pbEncoding.Value = 100;
                e.Finish();

            return saveFileDialog1.FileName;
        }