Click here to Skip to main content
11,577,710 members (63,236 online)
Click here to Skip to main content

Tagged as

How to convert BMP to GIF in C#

, 1 Dec 2010 CPOL 3.3K 2
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)

Share

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.

You may also be interested in...

Comments and Discussions

 
GeneralYeah, good idea to get rid of the magic constants. Pin
Walt Fair, Jr.20-Dec-10 12:10
subeditorWalt Fair, Jr.20-Dec-10 12:10 

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 | Terms of Use | Mobile
Web04 | 2.8.150603.1 | Last Updated 1 Dec 2010
Article Copyright 2010 by Andrew Rissing
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid