DCSIMG
How to convert an image to 32 bit BMP - Arik Poznanski's Blog

Arik Poznanski's Blog

It CAN be done with .NET

News

MVP

MCC

CodeProject MVP

MCPD

MCTS

Subscribe to my blog by email

Arik Poznanski LinkedIn Profile

Email: arik.com at gmail dot com
or, use this form

Locations of visitors to this page


Sela Group

Sela Canada

DZone MVB

Links

Official Blogs

WPF / SL Blogs

Developers Blogs

How to convert an image to 32 bit BMP

BMP image format can be saved in several different pixel format. Some programs and APIs requires their resources to be in 32bit BMP. Unfortunately, Microsoft Paint support saving only 24bit BMPs.

Since this issue is raised a lot when dealing with Windows Ribbon Framework I’ve decided to solve it once and for all. I’ve written a small console application that converts images into 32bit BMPs.

you can get convert2bmp.exe here, under “Other Available Downloads”.

Using the program

convert2bmp <source> <target>

for example: convert2bmp my24bit.BMP my32bit.BMP

What the program does

  • Load the image
  • Set the white color as the transparent color, thus making use of the alpha channel and forcing the image to be 32bit
  • Save the image

Source Code (C#)
Basically it looks like this:

Bitmap bmp = Image.FromFile(sourceFilename) as Bitmap;
bmp.MakeTransparent(Color.White);
bmp.Save(targetFilename, ImageFormat.Bmp);

Of course the actual version is 10 times longer due to error handling code.

That’s it for now,
Arik Poznanski.

kick it on DotNetKicks.com Shout it

Comments

No Comments