Click here to Skip to main content
15,881,281 members
Articles / Programming Languages / C#
Alternative
Tip/Trick

How to convert BMP to GIF in C#

Rate me:
Please Sign up or sign in to vote.
4.84/5 (11 votes)
2 Dec 2010CPOL 9.7K   5  
Very nice work. I would add a bit of reformatting and place it in all in method:public static void BitmapToGIF(string BitmapFile, string GIFFile){ using (Bitmap bitMap = new Bitmap(BitmapFile)) { //var codecInfo = GetEncoderInfo(ImageFormat.Gif); var...
Very nice work. I would add a bit of reformatting and place it in all in method:

C#
public static void BitmapToGIF(string BitmapFile, string GIFFile)
{
    using (Bitmap bitMap = new Bitmap(BitmapFile))
    {
            //var codecInfo = GetEncoderInfo(ImageFormat.Gif);
            var codecInfo = ImageCodecInfo.GetImageEncoders().FirstOrDefault(x => x.FormatID == ImageFormat.Gif.Guid);

            using (var paramsEncoder = new EncoderParameters(2))
            {
                paramsEncoder.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Compression, (long)EncoderValue.CompressionLZW);
                paramsEncoder.Param[1] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 0L);
                bitMap.Save(GIFFile, codecInfo, paramsEncoder);
            }
    }
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
CEO Marois Consulting
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --