Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

How can i convert more then 1000 png files format to gif format faster ?

$
0
0

This is the code i'm using now:

for (int i = mtpStart; i < mtpEnd; i++)
            {
                    if (bgw.CancellationPending == true)
                    {
                        pictureBox1.Image.Dispose();
                        pictureBox1.Image = Properties.Resources.Weather_Michmoret;
                        e.Cancel = true;
                        gifImage.Dispose();
                        File.Delete(previewFileName);
                        makeGif = false;
                        break;
                    }
                else
                {
                    try
                    {
                        String FileName = tempRadarPngToGifDirectory + "\\" + Counter.ToString("D6") + ".Gif";
                        gifImage = Image.FromFile(pngFileInfo[i].FullName);
                        gifImage.Save(FileName, System.Drawing.Imaging.ImageFormat.Gif);
                        gifImage.Dispose();
                        Counter += 1;
                        myGifList.Add(FileName);
                        percentage = Counter * 100 / total;//(total / 100) * Counter;
                        bgw.ReportProgress(percentage);

                    }
                    catch (Exception ex)
                    {
                        
                    }
                }
            }

For example mtpStart = 6318 and mtpEnd = 8673 so the number of files to convert is: 2357.

The problem is the saving part(the converting part)  that is taking a very long time:

String FileName = tempRadarPngToGifDirectory + "\\" + Counter.ToString("D6") + ".Gif";
                        gifImage = Image.FromFile(pngFileInfo[i].FullName);
                        gifImage.Save(FileName, System.Drawing.Imaging.ImageFormat.Gif);
                        gifImage.Dispose();

So i thought maybe to save it to convert it in the memory like this:

using (var ms = new MemoryStream())
                        {                           
                            gifImage.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
                        }

I'm just not sure where the file it self the variable FileName is coming in with this MemoryStream and also if that will be faster ? Or maybe there is another way to make the convertion faster ?


Viewing all articles
Browse latest Browse all 31927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>