Click here to Skip to main content
15,881,092 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.
5.00/5 (7 votes)
1 Dec 2010CPOL 9.5K   2   1
I'd recommend a minor tweak to your code to remove the 'magic' string of the mimeType from the code, using the following:static void Main(string[] args){ Bitmap bitMap = new Bitmap(@"test.bmp"); var codecInfo = GetEncoderInfo(ImageFormat.Gif); var paramsEncoder = new...
I'd recommend a minor tweak to your code to remove the 'magic' string of the mimeType from the code, using the following:

C#
static void Main(string[] args)
{
    Bitmap bitMap = new Bitmap(@"test.bmp");
 
    var codecInfo = GetEncoderInfo(ImageFormat.Gif);
 
    var paramsEncoder = new EncoderParameters(2);
    paramsEncoder.Param[0] = new EncoderParameter(Encoder.Compression, (long)EncoderValue.CompressionLZW);
    paramsEncoder.Param[1] = new EncoderParameter(Encoder.Quality, 0L);
 
    bitMap.Save("Output.gif", codecInfo, paramsEncoder);
}
 
private static ImageCodecInfo GetEncoderInfo(ImageFormat format)
{
    return ImageCodecInfo.GetImageEncoders().FirstOrDefault(x => x.FormatID == format.Guid);
}

License

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


Written By
Architect
United States United States
Since I've begun my profession as a software developer, I've learned one important fact - change is inevitable. Requirements change, code changes, and life changes.

So..If you're not moving forward, you're moving backwards.

Comments and Discussions

 
GeneralYeah, good idea to get rid of the magic constants. Pin
Dr.Walt Fair, PE20-Dec-10 12:10
professionalDr.Walt Fair, PE20-Dec-10 12:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.