private void tmrAnimation_Tick(object sender, EventArgs e) { if (anim.CurrentMs < 0 || anim.CurrentMs > anim.Flow.TotalDuration) { tmrAnimation.Enabled = false; btnStop.Text = "Start"; } //if (curMs > anim.Flow.TotalDuration) // tmrAnimation.Enabled = false; bool needToUpdate = anim.NextFrame(25); if (needToUpdate) { picPreview.Image = AnimationDrawer.GetImageFromFrame(anim, chkDisplayDebugInfo.Checked); DrawZoom(mousex, mousey); picPreview.Refresh(); msLastUpdated = anim.CurrentMs; frameCount++; } lblStatus.Text = anim.CurrentMs.ToString() + " " + msLastUpdated.ToString() + " frames: " + frameCount; lblDescription.Text = anim.CurrentTimeBlock.Description; // UpdateAnimList(); }
private void SaveGif(object filename) { List <string> framePaths = new List <string>(); List <int> delays = new List <int>(); if (!Directory.Exists("output")) { Directory.CreateDirectory("output"); } AnimationManager anim = new AnimationManager(xmlFile); long ms = 0; int FRAME_MS = 50; long lastUpdateMs = 0; long lastProgressRefresh = DateTime.Now.Ticks; while (ms < anim.Flow.TotalDuration) { bool needToUpdate = anim.NextFrame(FRAME_MS); if (needToUpdate) { Image img = AnimationDrawer.GetImageFromFrame(anim, false); string framePath = "output\\frame" + framePaths.Count + ".gif"; OctreeQuantizer quantizer = new OctreeQuantizer(255, 4); using (Bitmap quantized = quantizer.Quantize(img)) { quantized.Save(framePath, ImageFormat.Gif); } framePaths.Add(framePath); int delay = (int)((ms - lastUpdateMs) / 10); if (delay <= 0) { delay = 1; } delays.Add(delay); lastUpdateMs = ms; if (DateTime.Now.Ticks - lastProgressRefresh > 10000000) { SetSaveGifProgress("Generating frames", (float)ms / (float)anim.Flow.TotalDuration); lastProgressRefresh = DateTime.Now.Ticks; } } ms += FRAME_MS; } GifCreator.GifCreator gifCreator = new GifCreator.GifCreator(); GifCreator.GifCreator.ProgressHandler progressHandler = new GifCreator.GifCreator.ProgressHandler(GifCreator_Progress); gifCreator.Progress += progressHandler; gifCreator.CreateAnimatedGif(framePaths, delays, filename.ToString()); gifCreator.Progress -= progressHandler; SetSaveGifProgress("Save complete", 1f); }
private void btnDraw_Click(object sender, EventArgs e) { if (anim == null) { return; } picPreview.Image = AnimationDrawer.GetImageFromFrame(anim, chkDisplayDebugInfo.Checked); DrawZoom(mousex, mousey); }