Link to home
Start Free TrialLog in
Avatar of icestac
icestac

asked on

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!
Avatar of jrram
jrram
Flag of United States of America image

Avatar of icestac
icestac

ASKER

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.
Avatar of icestac

ASKER

I just ended up finding a thrid party utility to convert the images... pngConverter by Incors
Avatar of icestac

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of DarthMod
DarthMod
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial