How to write an image in GIF format

I would like a function that takes in a System.Image object and a file name and will save the Image to the file in GIF format.

void ConvertToGif(System.Image img, string gifFileName)
{
   // Save img to gifFileName as Gif...
}

Please take into account transparency

Thanks!
LVL 3
icestacAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

icestacAuthor Commented:
Those articles were not really helpful.  I have gotten to this point, but the transparency does not work.

string [] images = System.IO.Directory.GetFiles(this.tbDir.Text, "*.png");

foreach (string image in images)
{
      try
      {
            Image i = Image.FromFile(image);
            string gif = System.IO.Path.ChangeExtension(image, ".gif");
            System.IO.FileStream fs = System.IO.File.Create(gif, 256);
            i.Save(fs, System.Drawing.Imaging.ImageFormat.Gif);
            fs.Close();
      }
      catch (Exception e2)
      {
            System.Diagnostics.Trace.WriteLine("Unable to convert image: " + e2.ToString());
      }
}


For the 500 points, I am really just looking for a function that I can copy and paste.
icestacAuthor Commented:
I just ended up finding a thrid party utility to convert the images... pngConverter by Incors
icestacAuthor Commented:
By the way, there is a Microsoft article that gets most of the way there (except it is in grayscale instead of color)

See Q319061
DarthModCommented:
PAQed with points (500) refunded

DarthMod
Community Support Moderator

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.