public static async Task ProcessImage( [QueueInput("uploads")] Message message, [BlobInput("uploads/{BlobName}")] Stream input, [BlobOutput("memes/{BlobName}")] Stream output) { var encoder = new AnimatedGifEncoder(); encoder.SetRepeat(0); int delay; var frames = ProcessInputFrames(input, message.OverlayText.ToUpperInvariant(), out delay); encoder.SetDelay(delay); using (var result = new MemoryStream()) { encoder.Start(result); var idx = 1; foreach (var frame in frames) { Console.WriteLine("Adding frame #{0}/{1}", idx, frames.Count); encoder.AddFrame(frame); idx++; } encoder.Finish(); result.Position = 0; result.CopyTo(output); } var uri = SetMetadataAndCleanup(message); await SendCompleteNotification(message, uri); }
private async void MainWindow_Loaded(object sender, RoutedEventArgs e) { await Task.Delay(100); var encoder = new AnimatedGifEncoder(); encoder.Start("output.gif"); encoder.SetRepeat(0); foreach (var frame in Enumerable.Range(0, 10)) { AddFrame(encoder); await Task.Delay(10); } encoder.Finish(); }
public void button1_Click(object sender, EventArgs e) { /* create Gif */ //you should replace filepath //find the root folder from here //var rs = imageFilePaths[0].ToString().LastIndexOf("\\"); //find the root folder using savedialog //Stream myStream; //SaveFileDialog saveFileDialog1 = new SaveFileDialog(); //saveFileDialog1.Filter = "Images (*.gif)|*.gif"; //saveFileDialog1.FilterIndex = 2; //saveFileDialog1.RestoreDirectory = true; //if (saveFileDialog1.ShowDialog() == DialogResult.OK) //{ // if ((myStream = saveFileDialog1.OpenFile()) != null) // { // outputfilepath=saveFileDialog1.FileName; // // Code to write the stream goes here. // } //} var rs = imageFilePaths[0].ToString().Substring(10).LastIndexOf("\\"); var outputfilepath1 = imageFilePaths[0].ToString().Substring(10).Substring(0, rs); textBox1.Text = outputfilepath; var file_name = textBox2.Text; //|| file_name.ToLower().IndexOf("gif"))>0 if (file_name.Equals("") ) { MessageBox.Show("enter a file name"); } outputfilepath = outputfilepath1 +"\\" + file_name + ".gif"; AnimatedGifEncoder es = new AnimatedGifEncoder(); es.Start(outputfilepath); es.SetDelay(500); //-1:no repeat,0:always repeat es.SetRepeat(0); for (int i = 0, count = imageFilePaths.Count; i < count; i++) { es.AddFrame(Image.FromFile(imageFilePaths[i].ToString().Substring(10))); } es.Finish(); }
private void c_PerformTrace_Click(object sender, EventArgs e) { const int s = 64; const int o = 10000000; this.c_PerformTrace.Enabled = false; this.c_OnlyComparisonDataCheckBox.Enabled = false; this.c_GenerateGIF.Enabled = false; this.ControlBox = false; this.m_EnableHandlers = () => PerformOperationRecursively( v => v.DataGenerated += this.HandleDataGenerated, this.m_Layer); this.m_DisableHandlers = () => PerformOperationRecursively( v => v.DataGenerated -= this.HandleDataGenerated, this.m_Layer); this.c_TraceProgress.Maximum = 0; PerformOperationRecursively( v => this.c_TraceProgress.Maximum += this.c_OnlyComparisonDataCheckBox.Checked ? 1 : 2, this.m_Layer); this.m_Bitmaps = new List<Bitmap>(); this.m_EnableHandlers(); var thread = new Thread(() => { int computations; this.m_Layer.GenerateData( -s + o, -s + o, -s + o, s * 2, s * 2, this.m_Layer.Algorithm.Is2DOnly ? 1 : s * 2, out computations); this.m_DisableHandlers(); if (this.IsHandleCreated) { this.Invoke(new Action(() => { this.SuspendLayout(); this.c_TraceImage.Enabled = true; this.c_TraceScrollbar.Enabled = true; this.c_TraceProgress.Value = 0; this.c_TraceProgress.Enabled = false; this.ControlBox = true; if (this.m_Bitmaps.Count == 0) { this.ResumeLayout(); MessageBox.Show(@"No images were generated from the trace, now closing.."); this.Close(); return; } this.c_TraceImage.Image = this.m_Bitmaps[0]; this.c_TraceScrollbar.Minimum = 0; this.c_TraceScrollbar.Maximum = this.m_Bitmaps.Count - 1; this.c_TraceScrollbar.Value = 0; this.ResumeLayout(); this.Rescale(this.m_Bitmaps[0]); // Generate GIF if desired. if (this.c_GenerateGIF.Checked) { using (var sfd = new SaveFileDialog()) { sfd.Title = @"Save GIF"; sfd.Filter = @"Animated GIFs|*.gif"; sfd.RestoreDirectory = true; sfd.AddExtension = true; if (sfd.ShowDialog() == DialogResult.OK) { var encoder = new AnimatedGifEncoder(); encoder.Start(sfd.FileName); encoder.SetDelay(1000); encoder.SetRepeat(0); foreach (var image in this.m_Bitmaps) encoder.AddFrame(image); encoder.Finish(); } } } })); } }) { IsBackground = true }; thread.Start(); }
public GifRecorder(FrameworkElement container, FrameworkElement root, string fileName, int fps) { _container = container; _root = root; _frameDelay = TimeSpan.FromMilliseconds(1000.0 / fps); _storyboardControllers = new List<StoryboardController>(); _renderTargetBitmap = new RenderTargetBitmap((int)_root.ActualWidth, (int)_root.ActualHeight, 96, 96, PixelFormats.Pbgra32); _writeableBitmap = new WriteableBitmap((int)_root.ActualWidth, (int)_root.ActualHeight, 96, 96, PixelFormats.Pbgra32, null); _encoder = new AnimatedGifEncoder(); _encoder.Start(fileName); _encoder.SetRepeat(0); _encoder.SetFrameRate(fps); CompositionTarget.Rendering += CompositionTarget_Rendering; }
private void SaveGif(List<Bitmap> frames) { var path = Path.Combine(_outputPath, "map.gif"); AnimatedGifEncoder e = new AnimatedGifEncoder(); e.Start(path); e.SetDelay(100); //-1:no repeat,0:always repeat e.SetRepeat(0); foreach (Bitmap bmp in frames) { e.AddFrame(bmp); } e.Finish(); }