Click here to Skip to main content
11,647,644 members (65,308 online)
Click here to Skip to main content

Tagged as

How to convert BMP to GIF in C#

, 19 Dec 2010 CPOL 29K 23
Rate this:
Please Sign up or sign in to vote.
How to convert BMP to GIF in C#
In this post, I will show you how to convert BMP file to GIF in C#. The first step you must do is to create a Bitmapobject. In this example, I passed filename to constructor of this object. Next you need to create ImageCodecInfoand choose the appropriate mime type of output format. You can set quality and compression of output image. In case you need to do this, you must create EncoderParametersobject which represents list of EncoderParameterobjects. This objects represent set of parameters which encoder uses for image encoding.
static void Main(string[] args)
{
    Bitmap myBitmap=new Bitmap(@"test.bmp");
    ImageCodecInfo myImageCodecInfo = GetEncoderInfo("image/gif"); ;
    EncoderParameter encCompressionrParameter = new EncoderParameter(System.Drawing.Imaging.Encoder.Compression, (long)EncoderValue.CompressionLZW); ;
    EncoderParameter encQualityParameter = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 0L);
    EncoderParameters myEncoderParameters = new EncoderParameters(2);
    myEncoderParameters.Param[0] = encCompressionrParameter;
    myEncoderParameters.Param[1] = encQualityParameter;
    myBitmap.Save("Output.gif", myImageCodecInfo, myEncoderParameters);
}
private static ImageCodecInfo GetEncoderInfo(String mimeType)
{
    int j;
    ImageCodecInfo[] encoders;
    encoders = ImageCodecInfo.GetImageEncoders();
    for (j = 0; j < encoders.Length; ++j)
    {
        if (encoders[j].MimeType == mimeType)
            return encoders[j];
    }
    return null;
}

License

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

Share

About the Author

Kanasz Robert
Architect The Staffing Edge & Marwin Cassovia Soft
Slovakia Slovakia
My name is Robert Kanasz and I have been working with ASP.NET, WinForms and C# for several years.
MCSD - Web Applications
MCSE - Data Platform
MCPD - ASP.NET Developer 3.5
- Web Developer 4
MCITP - Database Administrator 2008
- Database Developer 2008
MCSA - SQL Server 2012
MCTS - .NET Framework 3.5, ASP.NET Applications
- SQL Server 2008, Database Development
- SQL Server 2008, Implementation and Maintenance
- .NET Framework 4, Data Access
- .NET Framework 4, Service Communication Applications
- .NET Framework 4, Web Applications
MS - Programming in HTML5 with JavaScript and CSS3 Specialist

Open source projects: DBScripter - Library for scripting SQL Server database objects


Please, do not forget vote

You may also be interested in...

Comments and Discussions

 
GeneralGracias por el codigo. Pin
MarcosBueno1-Mar-15 17:29
memberMarcosBueno1-Mar-15 17:29 
QuestionQuality Pin
Nicke Da Silva Manarin9-Oct-13 17:10
memberNicke Da Silva Manarin9-Oct-13 17:10 
GeneralReason for my vote of 5 very nice Pin
hoolly25-Dec-11 22:35
memberhoolly25-Dec-11 22:35 
GeneralRe: Reason for my vote of 5very nice Pin
Kanasz Robert21-Oct-13 2:15
mvpKanasz Robert21-Oct-13 2:15 
GeneralGood tip! Pin
Walt Fair, Jr.20-Dec-10 12:09
subeditorWalt Fair, Jr.20-Dec-10 12:09 
GeneralRe: Good tip! Pin
Kanasz Robert21-Oct-13 2:15
mvpKanasz Robert21-Oct-13 2:15 
GeneralReason for my vote of 1 No color mapping... Pin
lolocmwa8-Dec-10 3:48
memberlolocmwa8-Dec-10 3:48 
GeneralReason for my vote of 3 Quite decent work. Pin
Toli Cuturicu4-Dec-10 7:43
memberToli Cuturicu4-Dec-10 7:43 
GeneralRe: Reason for my vote of 3Quite decent work. Pin
Kanasz Robert21-Oct-13 2:15
mvpKanasz Robert21-Oct-13 2:15 
GeneralReason for my vote of 5 Good one Pin
thatraja3-Dec-10 1:51
mvpthatraja3-Dec-10 1:51 
Reason for my vote of 5
Good one
GeneralRe: Reason for my vote of 5Good one Pin
Kanasz Robert21-Oct-13 2:15
mvpKanasz Robert21-Oct-13 2:15 
GeneralReason for my vote of 1 So... Pin
T-luv1-Dec-10 8:27
memberT-luv1-Dec-10 8:27 

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.150804.2 | Last Updated 19 Dec 2010
Article Copyright 2010 by Kanasz Robert
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid