private void EncodeThread() { MemoryStream mem = new MemoryStream(); GifCreator gif = new GifCreator(); gif.AlphaColor = Color.HotPink; gif.HQMode = this.HQMode; gif.SetFPS(this.RealFPS); gif.Start(mem); HPStopwatch watch = new HPStopwatch(); watch.Start(); Thread.Sleep(1); watch.Stop(); watch.Start(); gif.WriteFrames(this.Frames.ToArray(), delegate(int framenum) { watch.Stop(); av.Add(watch.GetElapsedTimeInMicroseconds() / 1000); if (av.Count > 20) av.RemoveAt(0); double eta = 0; foreach (double num in av) eta += num; eta /= av.Count; eta *= this.Frames.Count - framenum; eta /= 1000; eta -= eta % 0.1; this.Invoke(new Action(delegate { this.progressBarEncoding.Value++; this.labelStatus.Text = "ETA: " + eta.ToString("0.0") + " seconds (" + ((double)mem.Length / 1024d / 1024d).ToString("0.00") + "MB)"; })); watch.Start(); }); gif.Finish(); this.Invoke(new Action(delegate { this.Close(); this.Callback(new DragCallback() { Type = DragCallbackType.Gif, Animation = mem }); })); }
private void buttonRender_Click(object sender, EventArgs e) { this.Enabled = false; int i = this.hScrollBar1.Value; if (i >= this.Frames.Length) i = this.Frames.Length - 1; if (this.pictureBox1.Image != null) this.pictureBox1.Image.Dispose(); int w = (int)((float)this.Frames[0].Width * ((float)this.trackScale.Value / 100f)); int h = (int)((float)this.Frames[0].Height * ((float)this.trackScale.Value / 100f)); // fix offset for gif encoder, i dont know why, i dont know how, once again, go f**k yourself. if (w % 4 != 0) w += 4 - w % 4; if (h % 4 != 0) h += 4 - h % 4; Bitmap bmp = new Bitmap(w, h); Graphics g = Graphics.FromImage(bmp); g.DrawImage(this.Frames[i], 0, 0, bmp.Width, bmp.Height); if (this.FrameEdits[i] != null) g.DrawImage(this.FrameEdits[i], 0, 0, bmp.Width, bmp.Height); g.Dispose(); MemoryStream mem = new MemoryStream(); GifCreator gif = new GifCreator(); gif.HQMode = this.comboQuality.Text == "High quality"; gif.Start(mem); gif.WriteFrames(new Bitmap[] { bmp }, null); gif.Finish(); mem.Position = 0; bmp = (Bitmap)Image.FromStream(mem); this.pictureBox1.Image = bmp; this.Enabled = true; }