Click here to Skip to main content
12,455,701 members (67,873 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

4.6K views
2 bookmarked
Posted

How to convert BMP to GIF in C#

, 1 Dec 2010 CPOL
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...

Pro
Pro

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    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.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160826.1 | Last Updated 1 Dec 2010
Article Copyright 2010 by Andrew Rissing
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid