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(); } }
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(); }
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("\\", "/")); }
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(); }
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; }
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(); } }