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

How to convert BMP to GIF in C#

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

About the Author

Andrew Rissing
Software Developer (Senior)
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. PinsubeditorWalt Fair, Jr.20-Dec-10 12:10 
Yeah, good idea to get rid of the magic constants.

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

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

| Advertise | Privacy | Mobile
Web04 | 2.8.140709.1 | Last Updated 1 Dec 2010
Article Copyright 2010 by Andrew Rissing
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid