Click here to Skip to main content
Click here to Skip to main content
Alternative Tip/Trick

Tagged as

How to convert BMP to GIF in C#

, 2 Dec 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
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:
 
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)

Share

About the Author

Kevin Marois
President Marois Consulting
United States United States
No Biography provided

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.1411028.1 | Last Updated 2 Dec 2010
Article Copyright 2010 by Kevin Marois
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid