private async Task ConvertToAnimatedGifFileAsync(string targetDirectory, string outputPath, float frameRate) { // 画像ファイルを名前昇順で全取得 var filePaths = Directory.GetFiles(targetDirectory) .Where(name => name.EndsWith(".jpg") || name.EndsWith(".png")) .OrderBy(name => name); await Task.Run(() => { using (var collection = new ImageMagick.MagickImageCollection()) { foreach (var filePath in filePaths) { collection.Add(filePath); } foreach (var item in collection) { item.AnimationDelay = (int)(1000.0f / frameRate / 10.0f); // 10 ms 単位 // item.Resize(100, (int)(100.0f / item.Width * item.Height)); } collection.Optimize(); collection.Write(outputPath); } }).ConfigureAwait(false); }
public async void Run() { //DateTime first = new DateTime(2017, 7, 9, 14, 50, 00); //DateTime last = new DateTime(2017, 7, 10, 14, 30, 00); //List<DateTime> dates = new List<DateTime>(); //dates.Add(first); //do //{ // dates.Add(dates.Last().AddMinutes(10)); //} while (dates.Last() < last && dates.Count < 160000000); //List<string> images = new List<string>(); //foreach (var date in dates) //{ // images.Add(await sateliteService.DownloadImage(date, false)); // Console.Clear(); // Console.WriteLine(dates.IndexOf(date)/dates.Count); // Console.WriteLine(dates.IndexOf(date)); //} var images = System.IO.Directory.GetFiles(@"D:\Temp"); using (ImageMagick.MagickImageCollection coll = new ImageMagick.MagickImageCollection()) { try { for (int i = 0; i < images.Length; i++) { coll.Add(new ImageMagick.MagickImage(images[i])); coll[i].AnimationDelay = 5; } } catch (Exception) { throw; } //coll.OptimizePlus(); coll.Write("D:\\earth2.gif"); } }