This is the code:
if (Form1.sf != null)
{
radarDI = new DirectoryInfo(Form1.sf);
radarFiles = radarDI.GetFiles("*.png");
for (int i = radarFiles.Length - 1; i >= 0; i--)
{
radarImage = Image.FromFile(radarFiles[i].Name);
radarImage.Save(FileName, System.Drawing.Imaging.ImageFormat.Gif);
myGifListRadar.Add(radarFiles[i].Name);
if (myGifListRadar.Count == 5)
{
break;
}
}
radar_animation.MakeGIF(myGifListRadar, @"d:\RadarGifAnimatoion.gif", 8, true);
}
I want to convert all the png files to gif.
Since I need to create animated gif and it’s getting only gif files.
So now im saving the png files to the hard disk make the convertion and then reading back the gif files from the hard disk:
radarImage.Save(FileName, System.Drawing.Imaging.ImageFormat.Gif);
FileName should be later on the files im saving and then reading back to use it.
The question is if there is any way to convert the files to gif without saving it to the hard disk first ? Some quicker way then saving the files to the hard disk convert then read them again as gif’s with FileInfo again ?
Just updated:
using (var ms = new MemoryStream())
{
if (Form1.sf != null)
{
radarDI = new DirectoryInfo(Form1.sf);
radarFiles = radarDI.GetFiles("*.png");
for (int i = radarFiles.Length - 1; i >= 0; i--)
{
radarImage = Image.FromFile(radarFiles[i].FullName);
radarImage.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
myGifListRadar.Add(radarFiles[i].Name);
if (myGifListRadar.Count == 5)
{
break;
}
}
}
radar_animation.MakeGIF(myGifListRadar, @"d:\RadarGifAnimatoion.gif", 8, true);
}
But now this part:
radarImage.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
myGifListRadar.Add(radarFiles[i].Name);
myGifListRadar is List how can I add now the radarImage to the List as string file name ?
Use
Image.Save(Stream, ImageFormat):Depending on how you are making a GIF with multiple frames, this might be unnecessary – can you just take the separate
Images and make the multi-frame GIF directly instead of making separate GIFs and then merging them?