Esempio n. 1
0
    static IEnumerator MakeGifRoutine(List <RenderTexture> textures, float frameLength, Stream output, bool closeWhenDone)
    {
        Game.instance.canRecord = false;
        var gifEncoder = new Gif.Components.AnimatedGifEncoder();

        gifEncoder.SetQuality(10);
        gifEncoder.SetRepeat(0);
        gifEncoder.SetDelay((int)(frameLength * 1000));

        gifEncoder.Start(output);
        int w   = textures[0].width;
        int h   = textures[0].height;
        var tex = new Texture2D(w, h, TextureFormat.ARGB32, false, true);

        var imageStart = new ManualResetEvent(false);

        Gif.Components.Image image = null;
        bool done      = false;
        bool processed = false;
        var  worker    = new Thread(() => {
            while (!done)
            {
                imageStart.WaitOne();
                imageStart.Reset();
                gifEncoder.AddFrame(image);
                processed = true;
            }
        });

        worker.Start();


        for (int picCount = 0; picCount < textures.Count; picCount++)
        {
            var tempTex = textures[picCount];
            RenderTexture.active = tempTex;
            tex.ReadPixels(new Rect(0, 0, w, h), 0, 0);
            RenderTexture.ReleaseTemporary(tempTex);
            image     = new Gif.Components.Image(tex);
            processed = false;
            imageStart.Set();
            while (!processed)
            {
                yield return(null);
            }
        }
        Game.instance.canRecord = true;

        done = true;

        textures.Clear();
        gifEncoder.Finish();

        DestroyImmediate(tex);
        output.Flush();
        if (closeWhenDone)
        {
            output.Close();
        }
    }
Esempio n. 2
0
		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 );
			}
		}
Esempio n. 3
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (listView1.Items.Count < 1)
            {
                MessageBox.Show("Drop source files first!", this.Text);
                return;
            }
            if ((file1.Text == "") && !ChooseFile())
            {
                return;
            }

            picture1.ImageLocation = "";

            Cursor.Current = Cursors.WaitCursor;

            String outputFilePath = file1.Text;
            AnimatedGifEncoder enc = new AnimatedGifEncoder();
            enc.Start(outputFilePath);
            enc.SetDelay((int)delay1.Value);
            //-1:no repeat,0:always repeat
            enc.SetRepeat(loop1.Checked ? 0 : -1);
            //for (int i = 0, count = imageFilePaths.Length; i < count; i++)
            foreach (ListViewItem i in listView1.Items)
            {
                enc.AddFrame(Image.FromFile(i.Text));
            }
            enc.Finish();

            picture1.ImageLocation = outputFilePath;

            Cursor.Current = Cursors.Default;
        }
Esempio n. 4
0
 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();
 }
Esempio n. 5
0
        public override void Record(object o)
        {
            var r = (RecData)o;
            String outputFilePath=r.path;

            if (File.Exists(outputFilePath))
            {
                File.Delete(outputFilePath);
            }
            rec = true;
            AnimatedGifEncoder en = new AnimatedGifEncoder();
            en.Start(outputFilePath);
            en.SetRepeat(0);

            while (rec)
            {
                if (!pause)
                {
                    Stopwatch st = new Stopwatch();
                    st.Start();
                    using (Bitmap bmpScreenCapture = new Bitmap(r.width, r.height))
                    {
                        using (Graphics g = Graphics.FromImage(bmpScreenCapture))
                        {
                            g.CopyFromScreen(r.pos,
                                             new Point(0, 0),
                                             bmpScreenCapture.Size,
                                             CopyPixelOperation.SourceCopy);
                            Rectangle cursorBounds = new Rectangle(new Point(Cursor.Position.X-r.pos.X,Cursor.Position.Y-r.pos.Y), Cursors.Default.Size);
                            Cursors.Default.Draw(g, cursorBounds);
                        }
                        en.AddFrame(bmpScreenCapture);
                        st.Stop();
                        var t = st.ElapsedMilliseconds;
                        en.SetDelay((int)(200+t));
                        if(200-t>0)
                        Thread.Sleep((int)(200 - t));
                    }

                }

            }

            en.Finish();
            en.SetDispose(0);
        }
Esempio n. 6
0
        private void GIFProgress_Load(object sender, EventArgs e)
        {
            new Task(() =>
            {
                AnimatedGifEncoder gifEncoder = new AnimatedGifEncoder();
                gifEncoder.Start(filename);
                gifEncoder.SetDelay(1000 / AnimationSpeed);
                gifEncoder.SetRepeat(Repeat ? 0 : 1);
                gifEncoder.SetQuality(Quality);
                foreach (Bitmap b in images)
                {
                    if (cancelled)
                    {
                        break;
                    }

                    gifEncoder.AddFrame(b);
                    b.Dispose();
                    if (!this.IsDisposed)
                    {
                        this.Invoke((Action)(() =>
                        {
                            if (!cancelled)
                            {
                                progressBar1.Value++;
                            }
                        }));
                    }
                }
                gifEncoder.Finish();
                if (cancelled)
                {
                    if (File.Exists(filename))
                    {
                        File.Delete(filename);
                    }
                }
                gifEncoder = null;
                finished   = true;
                if (!this.IsDisposed)
                {
                    this.Invoke((Action)(() => this.Close()));
                }
            }).Start();
        }
Esempio n. 7
0
File: Form1.cs Progetto: GregXP/XP
 private void CreateGIF(String outputFilePath)
 {
     /* create Gif */
     AnimatedGifEncoder e = new AnimatedGifEncoder();
     e.Start(outputFilePath);
     e.SetDelay((int)_udTimer.Value);
     //-1:no repeat,0:always repeat
     e.SetRepeat(0);
     e.SetTransparent(Color.Red);
     foreach (PictureBox pb in _fpImages.Controls)
     {
         if (pb != null && pb.Image != null)
         {
             e.AddFrame(pb.Image);
         }
     }
     e.Finish();
 }
Esempio n. 8
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();
        }
Esempio n. 9
0
        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);
            }
        }
Esempio n. 10
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());
        }
 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);
     }
 }
Esempio n. 12
0
        // Unfortunately GifBitmapEncoder doesn't support adding a metadata so I used other solution which is NGif.
        private void btnSaveGIF_Click(object sender, EventArgs e)
        {
            SaveFileDialog dialog = new SaveFileDialog();
            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                AnimatedGifEncoder encoder = new AnimatedGifEncoder();
                encoder.Start(dialog.FileName);
                encoder.SetRepeat(0);
                encoder.SetTransparent(System.Drawing.Color.Black);

                for (int i = 0; i < bitmapList.Count; ++i)
                {
                    Bitmap newBitmap = new Bitmap(bitmapList[i]);

                    Graphics g = Graphics.FromImage(newBitmap);
                    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                    g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                    g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
                    // newBitmap에 Entity들을 그리고 저장한다.
                    for (int entityIdx = 0; entityIdx < EntityList.Count; ++entityIdx )
                    {
                        Entity entity = EntityList[entityIdx];
                        if (entity.EntityType == Entity.eEntityType.Text)
                        {                                                        
                            g.DrawString(entity.text, DefaultFont, System.Drawing.Brushes.Black, (PointF)entity.pos[i]);
                        }
                    }

                    g.Flush();

                    encoder.AddFrame(newBitmap);
                }
                encoder.Finish();
            }
        }
Esempio n. 13
0
 private void SaveAsGif(IList<Bitmap> bitmaps, string path)
 {
     path += ".gif";
    AnimatedGifEncoder encoder = new AnimatedGifEncoder();
     encoder.Start(path);
     encoder.SetRepeat(0);
     encoder.SetDelay(FrameDelayPicker.Value ?? 500);
     for (int ii = 0; ii < _flipbook.PageCount; ii++)
     {
         encoder.AddFrame(bitmaps[ii]);
     }
     encoder.Finish();
 }
        public void RenderToGIF(Image[] images)
        {
            string outPath = "";
            Start:
            if (!String.IsNullOrEmpty(ScreenCapBgLocText.Text))
            {
                try
                {
                    outPath = ScreenCapBgLocText.Text;
                    if (!Directory.Exists(outPath))
                        Directory.CreateDirectory(outPath);

                    DirectoryInfo dir = new DirectoryInfo(outPath);
                    FileInfo[] files = dir.GetFiles();
                    int i = 0;
                    string name = "Animation";
                Top:
                    foreach (FileInfo f in files)
                        if (f.Name == name + i + ".gif")
                        {
                            i++;
                            goto Top;
                        }
                    outPath += "\\" + name + i + ".gif";
                }
                catch { }
            }
            else
            {
                ScreenCapBgLocText.Text = Application.StartupPath + "\\ScreenCaptures";
                goto Start;
            }

            AnimatedGifEncoder e = new AnimatedGifEncoder();
            e.Start(outPath);
            e.SetDelay(1000 / (int)pnlPlayback.numFPS.Value);
            e.SetRepeat(0);
            e.SetQuality(1);
            using (ProgressWindow progress = new ProgressWindow(this, "GIF Encoder", "Encoding, please wait...", true))
            {
                progress.TopMost = true;
                progress.Begin(0, images.Length, 0);
                for (int i = 0, count = images.Length; i < count; i++)
                {
                    if (progress.Cancelled)
                        break;

                    e.AddFrame(images[i]);
                    progress.Update(progress.CurrentValue + 1);
                }
                progress.Finish();
                e.Finish();
            }

            if (InterpolationEditor != null)
                InterpolationEditor.Enabled = true;
            ModelPanel.Enabled = true;
            Enabled = true;

            MessageBox.Show("GIF successfully saved to " + outPath.Replace("\\", "/"));
        }
Esempio n. 15
0
    static IEnumerator MakeGifRoutine(List<RenderTexture> textures, float frameLength, Stream output, bool closeWhenDone)
    {
        var gifEncoder = new Gif.Components.AnimatedGifEncoder();
        gifEncoder.SetQuality(10);
        gifEncoder.SetRepeat(0);
        gifEncoder.SetDelay((int)(frameLength * 1000));

        gifEncoder.Start(output);
        int w = textures[0].width;
        int h = textures[0].height;
        var tex = new Texture2D(w,h, TextureFormat.ARGB32, false, true);

        var imageStart = new ManualResetEvent(false);
        Gif.Components.Image image = null;
        bool done = false;
        bool processed = false;
        var worker = new Thread(() => {
            while (!done) {
                imageStart.WaitOne();
                imageStart.Reset();
                gifEncoder.AddFrame(image);
                processed = true;
            }
        });
        worker.Start();

        for (int picCount = 0; picCount < textures.Count; picCount++) {
            var tempTex = textures[picCount];
            RenderTexture.active = tempTex;
            tex.ReadPixels(new Rect(0, 0, w, h), 0, 0);
            RenderTexture.ReleaseTemporary(tempTex);
            image = new Gif.Components.Image(tex);
            processed = false;
            imageStart.Set();
            while (!processed) {
                yield return null;
            }

        }
        done = true;

        textures.Clear();
        gifEncoder.Finish();

        DestroyImmediate(tex);
        output.Flush();
        if (closeWhenDone) {
            output.Close();
        }
    }
Esempio n. 16
0
        private void SaveImageThread(AnimationHandeler hand, bool removeAndReturn)
        {
            if (removeAndReturn)
            {
                trackingobjs.Remove(hand);
                return;
            }
            string FileName = GetFile(hand.Obj);

            Bitmap[] bmps = hand.bitmaps.ToArray<Bitmap>();
            trackingobjs.Remove(hand);
            AnimatedGifEncoder gif = new AnimatedGifEncoder();

            gif.Start(FileName);
            gif.SetDelay(50);
            gif.SetRepeat(0);

            foreach (Bitmap bmp in bmps)
                gif.AddFrame(bmp);

            gif.Finish();
        }
Esempio n. 17
0
        private void dlg_exportFile_FileOk(object sender, System.ComponentModel.CancelEventArgs e)
        {
            AnimatedGifEncoder x = new AnimatedGifEncoder();
            x.Start(dlg_exportFile.FileName);
            x.SetDelay(1000 / Program.ToolboxForm.frameRate);
            x.SetRepeat(0);

            if (dlg_exportFile.FileName.EndsWith(".gif"))
            {
                for (int i = 0;Program.TimelineForm.hasFrames(i);i++)
                {
                    x.AddFrame(Program.TimelineForm.saveFrame(i));
                }
            }

            x.Finish();
        }
		private void exportButton_Click(object sender, RoutedEventArgs e)
		{
#if false

			var encoder = new GifBitmapEncoder();
			for (var i = 0; i <= 100; i++)
			{
				var chapters = db.PlanetOwnerHistories.Where(h => h.Turn == i);
				foreach (var chapter in chapters) ApplyHistoryItem(chapter);
				mapCanvas.UpdateLayout();

				var bitmap = new RenderTargetBitmap((int)viewBox.ActualWidth, (int)viewBox.ActualHeight, 96 * (int)viewBox.ActualWidth, 96 * (int)viewBox.ActualHeight, PixelFormats.Pbgra32);
				bitmap.Render(mapCanvas);
				encoder.Frames.Add(BitmapFrame.Create(bitmap));
				Debug.WriteLine(i);
			}
			string path = @"C:\Users\Nubtron\Desktop\replay.gif";
			var fileStream = new FileStream(path, FileMode.Create);
			encoder.Save(fileStream);
			fileStream.Close();
#endif
#if true			
			
                var anim = new AnimatedGifEncoder();
                anim.SetSize(512, 512);
                anim.SetDelay(200);
                anim.Start(File.OpenWrite(@"c:\temp\pw_replay.gif"));    
            foreach (var chapters in db.PlanetOwnerHistories.Where(x=>x.Planet.Galaxy.IsDefault).GroupBy(x=>x.Turn).OrderBy(x=>x.Key))
			    {
                    foreach (var chapter in chapters) ApplyHistoryItem(chapter);
			        mapCanvas.UpdateLayout();

			        var bitmap = new RenderTargetBitmap(512, 512, 96*512, 96*512, PixelFormats.Pbgra32);
			        bitmap.Render(mapCanvas);

			        var encoder = new BmpBitmapEncoder();
			        encoder.Frames.Add(BitmapFrame.Create(bitmap));
                    var ms = new MemoryStream();
                    encoder.Save(ms);
                    anim.AddFrame(System.Drawing.Image.FromStream(ms));
			    }
            anim.Finish();
					
#endif
		}
        private void WriteImageAnimated()
        {
            if (tempImages != null && tempImages.Count > 0)
            {
                String outputFilePath = FileSystem.GetUniqueFilePath(WorkflowConfig, Engine.ImagesDir,
                                                                     new NameParser(NameParserType.EntireScreen).Convert
                                                                         (WorkflowConfig.ConfigFileNaming.EntireScreenPattern));

                switch (WorkflowConfig.ImageFormatAnimated)
                {
                    case AnimatedImageFormat.PNG:
                        outputFilePath += ".png";
                        var apng = new Apng();
                        foreach (Image img in tempImages)
                        {
                            apng.AddFrame(new Bitmap(img), WorkflowConfig.ImageAnimatedFramesDelay * 1000, 1000);
                        }

                        apng.WriteApng(outputFilePath);
                        break;

                    default:
                        outputFilePath += ".gif";
                        var enc = new AnimatedGifEncoder();
                        enc.Start(outputFilePath);
                        enc.SetDelay(WorkflowConfig.ImageAnimatedFramesDelay * 1000);
                        enc.SetRepeat(0);
                        foreach (Image img in tempImages)
                        {
                            enc.AddFrame(img);
                        }
                        enc.Finish();
                        break;
                }

                UpdateLocalFilePath(outputFilePath);
                DebugHelper.WriteLine("Wrote animated image: " + outputFilePath);
                tempImages.Clear();
            }
        }
Esempio n. 20
0
		public void Generate(string method,long seed,long X, long Y,object[] args)
		{
            if (!Directory.Exists("terrain"))
                Directory.CreateDirectory("terrain");

			
            IVoxelChannel vc = MakeCopy();
            if (TerrainGenerators.ContainsKey(method))
            {
                TerrainGenerators[method].Initialize(mMaterials, seed);
                TerrainGenerators[method].Generate(ref vc,X,Y);
                Voxels = (vc as VoxelChannel).Voxels;
            }
            else
            {
                Console.WriteLine("[TERRAGEN] Terrain generation module \"{0}\" not installed.", method);
                return;
            }
			Image image =  new Bitmap(XScale,YScale);
            double[,] hm = GetDoubles();
            for(int x=0;x<XScale;x++)
            {
                for(int y=0;y<YScale;y++)
                {
                    int c = (int)(255.0d*(hm[x,y]/256d));
                    (image as Bitmap).SetPixel(x,255-y,Color.FromArgb(c,c,c));
                }
            }
			image.Save("terrain/GEN.png",System.Drawing.Imaging.ImageFormat.Png);
			image.Dispose();
			AnimatedGifEncoder e = new AnimatedGifEncoder();
			e.Start( "terrain/SLICE.gif" );
			e.SetDelay(250);
			//-1:no repeat,0:always repeat
			
			e.SetRepeat(0);

			for(int x=0;x<XScale;x++)
			{
				image = new Bitmap(YScale,ZScale);
				for(int y=0;y<YScale;y++)
				{
					//Console.WriteLine();
					for(int z=0;z<ZScale;z++)
					{
						if(IsSolid(x,y,z))
							(image as Bitmap).SetPixel(y,ZScale-z-1,Color.FromArgb(255,255,255));
						else
							(image as Bitmap).SetPixel(y,ZScale-z-1,Color.FromArgb(000,000,000));
					}
				}
				Console.CursorLeft=0;
				Console.Write(" * {0}% ({1}/{2}) frames added...",(int)(((float)(x+1)/((float)XScale))*100f),x+1,XScale);
				e.AddFrame((Image)image.Clone());
				image.Dispose();
			}
			Console.WriteLine();
			e.Finish();
		}
        internal void DoButterTransform_gif(string filepath, string targetfile, int frameCount, bool encrypt, string password = "")
        {
            byte[] fileAsBytes = readFileAsBytes(filepath);
            byte[] dataFrame = getDataFrame(fileAsBytes, encrypt, password);

            int byteLengthPerGifFrame = (int)Math.Ceiling((double)dataFrame.Length / frameCount);
            List<int> frameDimensions = calculateReqImgDim(byteLengthPerGifFrame);

            List<Bitmap> gifFrames = new List<Bitmap>();
            for (int i = 0; i < frameCount; i++ )
            {
                List<byte> subFrame = new List<byte>();
                for(int k = i * byteLengthPerGifFrame; k<i*byteLengthPerGifFrame + byteLengthPerGifFrame; k++)
                {
                    subFrame.Add(dataFrame[k]);
                }
                gifFrames.Add(bytesToBitmap(subFrame.ToArray(),frameDimensions[0],frameDimensions[1]));
            }

            AnimatedGifEncoder ec = new AnimatedGifEncoder();
            ec.SetQuality(100);
            ec.Start(targetfile);

            ec.SetDelay(500);
            //-1:no repeat,0:always repeat
            ec.SetRepeat(0);
            for (int i = 0, count = gifFrames.Count; i < count; i++)
            {
                ec.AddFrame(gifFrames[i]);
            }
            ec.Finish();
        }
Esempio n. 22
0
        private void buttonStop_Click(object sender, EventArgs e)
        {
            this.timerFrame.Enabled = false;

            this.Hide();
            this.animBox.Hide();

            DragCallback callback = new DragCallback() { Type = DragCallbackType.Animation, Animation = new MemoryStream() };

            AnimatedGifEncoder encoder = new AnimatedGifEncoder();
            encoder.Start(callback.Animation);
            encoder.SetDelay(this.timerFrame.Interval);
            encoder.SetRepeat(0);

            this.addon.ProgressBar.Start("Encoding Gif", this.frames.Count, false);

            for(int i = 0; i < this.frames.Count; i++) {
                if(this.addon.ProgressBar.Canceled) {
                    this.Close();
                    return;
                }

                encoder.AddFrame(this.frames[i]);
                this.addon.ProgressBar.Set(i);
            }

            encoder.Finish();

            this.addon.ProgressBar.Done();

            this.doneDragging(callback);
            this.Close();
        }
Esempio n. 23
0
        public void ExportFrames(string palette, string filename, ImageFormat ExportFormat)
        {
            lastpal = palette;

            if (oldshp == false)
            {
                FramesEx = new Image[shp.ImageCount + 1];
                BitmapEx = new Bitmap[shp.ImageCount + 1];
                FramesEx[0] = new Bitmap(shp.Width, shp.Height);

                for (int i = 1; i <= (int)(shp.ImageCount / 2); i++)
                {
                    FileStream P = new FileStream(palette, FileMode.Open, FileAccess.Read);
                    var p = new Palette(P, true);
                    P.Close();
                    FramesEx[i] = RenderShp(p, i - 1);
                }
                for (int i = (int)(shp.ImageCount / 2); i <= shp.ImageCount; i++)
                {
                    FileStream P = new FileStream(palette, FileMode.Open, FileAccess.Read);
                    var p = new Palette(P, transparentColorsToolStripMenuItem.Checked);
                    P.Close();
                    FramesEx[i] = RenderShp(p, i - 1);
                }
                if (shp.ImageCount > 1)
                {
                    if (shadowToolStripMenuItem.Checked)
                    {
                        if (shp.ImageCount > 1)
                        {
                            var bitmap = new Bitmap(shp.Width, shp.Height);
                            var fbitmap = new Bitmap(shp.Width, shp.Height);
                            var obitmap = new Bitmap(shp.Width, shp.Height);

                            for (int i = 1; i <= (int)(shp.ImageCount / 2); i++)
                            {
                                BitmapEx[i] = new Bitmap(shp.Width, shp.Height);
                                bitmap = (Bitmap)FramesEx[i];
                                obitmap = (Bitmap)FramesEx[i];
                                fbitmap = (Bitmap)FramesEx[i + (int)(shp.ImageCount / 2)];
                                using (var g = System.Drawing.Graphics.FromImage(fbitmap))
                                    g.DrawImage(obitmap, 0, 0);
                                using (var g = System.Drawing.Graphics.FromImage(bitmap))
                                    g.DrawImage(fbitmap, 0, 0);
                                BitmapEx[i] = bitmap;
                            }
                            frexp = (int)(shp.ImageCount / 2);
                        }
                    }
                    if (turretToolStripMenuItem.Checked)
                    {
                        if (shp.ImageCount > 1)
                        {
                            var bitmap = new Bitmap(shp.Width, shp.Height);
                            var fbitmap = new Bitmap(shp.Width, shp.Height);
                            int limit = (int)(shp.ImageCount / 2);
                            if ((shadowToolStripMenuItem.Checked) || (palf == PaletteFormat.ts))
                            {
                                limit = (int)(limit / 2);
                            }

                            for (int i = 1; i <= limit; i++)
                            {
                                BitmapEx[i] = new Bitmap(shp.Width, shp.Height);
                                bitmap = (Bitmap)FramesEx[i];
                                fbitmap = (Bitmap)FramesEx[i + limit];

                                using (var g = System.Drawing.Graphics.FromImage(bitmap))
                                    g.DrawImage(fbitmap, (int)numTurretOffsetX.Value, (int)numTurretOffsetY.Value);
                                BitmapEx[i] = bitmap;
                            }
                            frexp = limit;
                        }
                    }
                }
                else
                {
                    for (int i = 1; i <= shp.ImageCount; i++)
                    {
                        BitmapEx[i] = new Bitmap(shp.Width, shp.Height);
                        BitmapEx[i] = (Bitmap)FramesEx[i];
                    }
                    frexp = shp.ImageCount;
                }
                if ((turretToolStripMenuItem.Checked == false) && (shadowToolStripMenuItem.Checked == false))
                {

                    for (int i = 1; i <= shp.ImageCount; i++)
                    {
                        BitmapEx[i] = new Bitmap(shp.Width, shp.Height);
                        BitmapEx[i] = (Bitmap)FramesEx[i];
                    }
                    frexp = shp.ImageCount;
                }
            }
            if (oldshp == true)
            {
                FramesEx = new Image[shpold.ImageCount + 1];
                BitmapEx = new Bitmap[shpold.ImageCount + 1];
                FramesEx[0] = new Bitmap(shpold.Width, shpold.Height);
                for (int i = 1; i <= (int)(shpold.ImageCount / 2); i++)
                {
                    FileStream P = new FileStream(palette, FileMode.Open, FileAccess.Read);
                    var p = new Palette(P, transparentColorsToolStripMenuItem.Checked);
                    P.Close();
                    FramesEx[i] = RenderShp(p, i - 1);
                }
                for (int i = (int)(shpold.ImageCount / 2); i <= shpold.ImageCount; i++)
                {
                    FileStream P = new FileStream(palette, FileMode.Open, FileAccess.Read);
                    var p = new Palette(P, transparentColorsToolStripMenuItem.Checked);
                    P.Close();
                    FramesEx[i] = RenderShp(p, i - 1);
                }
                if (shpold.ImageCount > 1)
                {
                if (shadowToolStripMenuItem.Checked)
                {
                    if (shpold.ImageCount > 1)
                    {
                        var bitmap = new Bitmap(shpold.Width, shpold.Height);
                        var fbitmap = new Bitmap(shpold.Width, shpold.Height);
                        var obitmap = new Bitmap(shpold.Width, shpold.Height);

                        for (int i = 1; i <= (int)(shpold.ImageCount / 2); i++)
                        {
                            BitmapEx[i] = new Bitmap(shpold.Width, shpold.Height);
                            bitmap = (Bitmap)FramesEx[i];
                            obitmap = (Bitmap)FramesEx[i];
                            fbitmap = (Bitmap)FramesEx[i + (int)(shpold.ImageCount / 2)];
                            using (var g = System.Drawing.Graphics.FromImage(fbitmap))
                                g.DrawImage(obitmap, 0, 0);
                            using (var g = System.Drawing.Graphics.FromImage(bitmap))
                                g.DrawImage(fbitmap, 0, 0);
                            BitmapEx[i] = bitmap;
                        }
                        frexp = (int)(shpold.ImageCount / 2);
                    }
                }
                if (turretToolStripMenuItem.Checked)
                {
                    if (shpold.ImageCount > 1)
                    {
                        var bitmap = new Bitmap(shpold.Width, shpold.Height);
                        var fbitmap = new Bitmap(shpold.Width, shpold.Height);
                        int limit = (int)(shpold.ImageCount / 2);
                        if ((shadowToolStripMenuItem.Checked) || (palf == PaletteFormat.ts))
                        {
                            limit = (int)(limit / 2);
                        }

                        for (int i = 1; i <= limit; i++)
                        {
                            BitmapEx[i] = new Bitmap(shpold.Width, shpold.Height);
                            bitmap = (Bitmap)FramesEx[i];
                            fbitmap = (Bitmap)FramesEx[i + limit];
                            using (var g = System.Drawing.Graphics.FromImage(bitmap))
                                g.DrawImage(fbitmap, (int)numTurretOffsetX.Value, (int)numTurretOffsetY.Value);
                            BitmapEx[i] = bitmap;
                        }
                        frexp = limit;
                    }
                }
                }
                else
                {
                    for (int i = 1; i <= shpold.ImageCount; i++)
                    {
                        BitmapEx[i] = new Bitmap(shpold.Width, shpold.Height);
                        BitmapEx[i] = (Bitmap)FramesEx[i];
                    }
                    frexp = shpold.ImageCount;
                }
                if ((turretToolStripMenuItem.Checked == false) && (shadowToolStripMenuItem.Checked == false))
                {
                    for (int i = 1; i <= shpold.ImageCount; i++)
                    {
                        BitmapEx[i] = new Bitmap(shpold.Width, shpold.Height);
                        BitmapEx[i] = (Bitmap)FramesEx[i];
                    }
                    frexp = shpold.ImageCount;
                }
            }
            remapmain = pbColor.BackColor;
            if (ExportFormat == ImageFormat.Png)
            {
                string changed = Path.ChangeExtension(filename, "");
                changed = changed.Replace('.', ' ');
                for (int i = 0; i < frexp; i++)
                {
                    int num = 0;
                    if (i > 0) { num = GetIntegerDigitCount(i); }
                    string filen = "000";
                    switch (num)
                    {
                        case 1:
                            filen = "000";
                            break;
                        case 2:
                            filen = "00";
                            break;
                        case 3:
                            filen = "00";
                            break;
                        case 4:
                            filen = "";
                            break;
                        default:
                            filen = "000";
                            break;
                    }
                    BitmapEx[i + 1].Save((changed + filen + i.ToString() + ".png"), ImageFormat.Png);
                }
            }
            if (ExportFormat == ImageFormat.Gif)
            {
                string changed = Path.ChangeExtension(filename, ".gif");
                String outputFilePath = changed;
                AnimatedGifEncoder e = new AnimatedGifEncoder();
                e.Start(outputFilePath);
                e.SetDelay(66);
                //-1:no repeat,0:always repeat
                e.SetRepeat(0);
                for (int i = 0; i < frexp; i++)
                {
                    e.AddFrame((Image)BitmapEx[i + 1]);
                }
                e.Finish();
            }
        }
Esempio n. 24
0
        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);
            }
        }
Esempio n. 25
0
 private void asGifToolStripMenuItem_Click(object sender, EventArgs e)
 {
     using (var sfd = new SaveFileDialog { Filter = "GIF (*.gif)|*.gif" })
         if (DialogResult.OK == sfd.ShowDialog())
         {
             tbPlay.Value = 1;
             Bitmap[] vgif;
             vgif = new Bitmap[tbPlay.Maximum];
             for (int i = 0; i < tbPlay.Maximum; i++)
             {
                 tbPlay.Value = i + 1;
                 vgif[i] = new Bitmap(pbFrame.Width, pbFrame.Height);
                 System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(pbFrame.Width, pbFrame.Height);
                 pbFrame.DrawToBitmap(bmp, pbFrame.ClientRectangle);
                 vgif[i] = bmp;
             }
             tbPlay.Value = 1;
             String outputFilePath = sfd.FileName;
             AnimatedGifEncoder ev = new AnimatedGifEncoder();
             ev.Start(outputFilePath);
             ev.SetDelay(66);
             //-1:no repeat,0:always repeat
             ev.SetRepeat(0);
             for (int i = 0; i < tbPlay.Maximum; i++)
             {
                 ev.AddFrame((Image)vgif[i]);
             }
             ev.Finish();
             MessageBox.Show("Viewport saved as " + Path.GetFileName(sfd.FileName));
         }
 }
Esempio n. 26
0
        void Calculate(bool bWithGif)
        {
            m_iVal++;
            bool bFlag = true;

            Image image;

            AnimatedGifEncoder gifEncoder = new AnimatedGifEncoder();
            String outputFilePath = "outputtest" + m_iVal.ToString() + "-" + m_iCount + ".gif";
            if (bWithGif)
            {
                gifEncoder.Start(outputFilePath);
                gifEncoder.SetDelay(500);
                gifEncoder.SetRepeat(0);
            }
            int iSteps = 0;
            m_iCount = m_Inner.m_Vertexes.Count;
            while (bFlag&&iSteps<20)
            {
                iSteps++;
                Dictionary<KeyValuePair<int, int>, double> bufEdges = new Dictionary<KeyValuePair<int, int>, double>();
                int i = 0, j = 0, k = 0;
                bFlag = false;
                double dSum = 0;
                for (i = 0; i < m_iCount; i++)
                {
                    for (j = 0; j < m_iCount; j++)
                    {
                        KeyValuePair<int, int> pp = new KeyValuePair<int, int>(i, j);
                        if (!m_Inner.m_Edges.ContainsKey(pp))
                            continue;
                        dSum = 0;
                        for (k = 0; k < m_iCount; k++)
                        {
                            KeyValuePair<int, int> pp1 = new KeyValuePair<int, int>(i, k);
                            if (!m_Inner.m_Edges.ContainsKey(pp1))
                                pp1 = new KeyValuePair<int, int>(k, i);
                            if (!m_Inner.m_Edges.ContainsKey(pp1))
                                continue;
                            KeyValuePair<int, int> pp2 = new KeyValuePair<int, int>(k, j);
                            if (!m_Inner.m_Edges.ContainsKey(pp2))
                                pp2 = new KeyValuePair<int, int>(j, k);
                            if (!m_Inner.m_Edges.ContainsKey(pp2))
                                continue;
                            if (m_Inner.m_Edges[pp1]==0)
                            {
                                m_Inner.m_Edges[pp1] = 0.001;
                            }
                            if (m_Inner.m_Edges[pp2] == 0)
                            {
                                m_Inner.m_Edges[pp2] = 0.001;
                            }
                            dSum += m_Inner.m_Edges[pp1] * m_Inner.m_Edges[pp2];
                        }
                        if (m_Inner.m_Edges[pp] == 0)
                        {
                            m_Inner.m_Edges[pp] = 0.001;
                        }
                        dSum *= (1 - Math.Pow(m_Inner.m_Edges[pp] / m_R, 2.0));
                        bufEdges.Add(pp, dSum);
                    }
                    Console.WriteLine(i.ToString()+" - ");
                }
                foreach (var el in bufEdges)
                {
                    m_Inner.m_Edges[el.Key] += el.Value;
                    if (m_Inner.m_Edges[el.Key] > 1)
                        m_Inner.m_Edges[el.Key] = 1;
                    if (m_Inner.m_Edges[el.Key] < -1)
                        m_Inner.m_Edges[el.Key] = -1;
                    if (m_Inner.m_Edges[el.Key] != -1 && m_Inner.m_Edges[el.Key] != 1)
                        bFlag = true;
                    m_Inner.SetEdgeStringVal(el.Key.Key, el.Key.Value, m_Inner.m_Edges[el.Key].ToString("0.#"));
                }
                dSum = 0;
                for (i = 0; i < m_iCount; i++)
                {
                    for (j = 0; j < m_iCount; j++)
                    {
                        KeyValuePair<int, int> pp = new KeyValuePair<int, int>(i, j);
                        if (!m_Inner.m_Edges.ContainsKey(pp))
                            continue;
                        for (k = 0; k < m_iCount; k++)
                        {
                            KeyValuePair<int, int> pp1 = new KeyValuePair<int, int>(i, k);
            //                            if (!m_Inner.m_Edges.ContainsKey(pp1))
            //                                pp1 = new KeyValuePair<int, int>(k, i);
                            if (!m_Inner.m_Edges.ContainsKey(pp1))
                                continue;
                            KeyValuePair<int, int> pp2 = new KeyValuePair<int, int>(k, j);
            //                            if (!m_Inner.m_Edges.ContainsKey(pp2))
            //                                pp2 = new KeyValuePair<int, int>(j, k);
                            if (!m_Inner.m_Edges.ContainsKey(pp2))
                                continue;
                            if ((m_Inner.m_Edges[pp1] * m_Inner.m_Edges[pp2] * m_Inner.m_Edges[pp]) > 0)
                                dSum++;
                        }
                    }
                    Console.WriteLine(i.ToString() + " + ");
                }
                m_Inner.SetBalanced(dSum);
                Console.WriteLine(dSum.ToString());

                picGraph.Image = image = Graphviz.RenderImage(GenerateText(), (string)comboBoxLayout.SelectedItem, "png");
                if (bWithGif)
                {
                    gifEncoder.AddFrame(image);
                }

                Application.DoEvents();
            }
            if (bWithGif)
            {
                gifEncoder.Finish();
            }
        }
Esempio n. 27
0
        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;
        }
 private void GenerateGif(string tempFolder)
 {
     try
     {
         Progress = 0;
         var files = Directory.GetFiles(tempFolder);
         AnimatedGifEncoder e = new AnimatedGifEncoder();
         e.Start(OutPutFile);
         e.SetDelay(1000/Fps);
         //-1:no repeat,0:always repeat
         e.SetRepeat(0);
         for (int i = 0, count = files.Length; i < count; i++)
         {
             Progress++;
             e.AddFrame(Image.FromFile(files[i]));
         }
         e.Finish();
     }
     catch (Exception ex)
     {
         OutPut.Insert(0, "Converting error :" + ex.Message);
     }
 }
Esempio n. 29
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();
 }