public void Save(string Filename, Point[] Solution) { // Start create bitmap Stopwatch S = Stopwatch.StartNew(); /*Bitmap B = new Bitmap(Width, Height); * * using (var FastB = new FastBitmap(B)) * { * for (int y = 0; y < Height; y++) * { * for (int x = 0; x < Width; x++) * { * B.SetPixel(x, y, _Walkable.GetValue(x, y) ? Color.White : Color.Black); * } * } * * foreach (Point P in Solution) * { * B.SetPixel(P.X, P.Y, Color.Red); * } * } * * S.Stop(); * Console.WriteLine($"Draw - {S.ElapsedMilliseconds}ms"); * // Finish create bitmap * * // Start save bitmap * S.Restart(); * * //_Gif.Save(@"out\output.gif"); * B.Save(Filename);*/ AnimatedGif Gif = new AnimatedGif(); int Gap = 1;// _States.Count / 100; for (int i = 0; i < _States.Count; i += Gap) { Gif.AddFrame(GridToBitmap(_States[i]), 1); } Gif.Save("solution.gif"); S.Stop(); Console.WriteLine($"Save - {S.ElapsedMilliseconds}ms"); // Finish save bitmap }
static bool Convert(string srcPath, string destPath, int destFPS) { var result = false; try { using (var srcGif = AnimatedGif.LoadFrom(srcPath)) { var fixedGifOffset = TimeSpan.FromMilliseconds(1000 / destFPS); var crntSrcOffset = new TimeSpan(); var crntDestOffset = new TimeSpan(); using (var destGif = new AnimatedGif()) { foreach (var srcFrame in srcGif) { crntSrcOffset += srcFrame.Delay; do { crntDestOffset += fixedGifOffset; var destFrame = (Image)srcFrame.Image.Clone(); destGif.AddFrame(destFrame, fixedGifOffset); }while (crntSrcOffset > crntDestOffset); } destGif.Save(destPath); Console.WriteLine($"Successfully converted \"{Path.GetFileName(srcPath)}\" to \"{Path.GetFileName(destPath)}\". New file contains {destGif.FrameCount} frames."); result = true; } } } catch (Exception) { } return(result); }
private static void Animate(List <Point> path, string mazeFilename, string mazeSolvedFilename, string outputFilename) { var gif = new AnimatedGif(); gif.AddFrame(Image.FromFile(mazeFilename), 50); if (path.Count > 2) { using (var m = Bitmap.FromFile("mario.gif")) { for (int i = 0; i < path.Count; i++) { if (i % 10 == 0 || i == path.Count - 1) { var image = Bitmap.FromFile(mazeFilename); var g = Graphics.FromImage(image); //note: disposing breaks the animated gif save method. g.DrawImage(m, new Point(path[i].X * SCALE, path[i].Y * SCALE)); if (i != path.Count - 1) { gif.AddFrame(image, 50); } else { gif.AddFrame(image, 100); } } } } } gif.AddFrame(Image.FromFile(mazeSolvedFilename), 100); File.Delete(outputFilename); gif.Save(outputFilename); }
public static void Main(string[] args) { Console.WriteLine("Hello World!"); var img1 = new Bitmap(8, 11); var img2 = new Bitmap(8, 11); var img3 = new Bitmap(8, 11); var img4 = new Bitmap(8, 11); SetPixels(img1, Color.Red); SetPixels(img2, Color.Blue); SetPixels(img3, Color.Orange); SetPixels(img4, Color.Green); using (var gif = new AnimatedGif(0)) { gif.AddFrame(img1, 100); gif.AddFrame(img2, 200); gif.AddFrame(img3, 300); gif.AddFrame(img4, 400); gif.Save("test.gif"); } }