How to convert an image to 32 bit BMP

4 באוקטובר 2009

תגיות: , , ,
5 תגובות

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

הוסף תגובה
facebook linkedin twitter email

כתיבת תגובה

האימייל לא יוצג באתר. (*) שדות חובה מסומנים

5 תגובות

  1. Héctor30 באוקטובר 2009 ב 12:50

    This may be a stupid question since I've not seen all the code nor I've played with it… but won't setting the white color to transparent ruin a lot of images?

    להגיב
  2. arik30 באוקטובר 2009 ב 13:40

    1. You are correct. It is an arbitrary color, which might not be suitable for some images.

    2. It won't ruin any image since the output is a new image.

    3. I use this tool all the time and white seems to be a good choice for me.

    4. I can add another parameter so that the user can specify the transparent color. This will make the tool a little harder to use beacuse of the new parameter which should be in a specific format. If i'll have more user requests I'll do it.

    להגיב
  3. Héctor30 באוקטובר 2009 ב 14:32

    2. I was talking about the resulting image, of course.

    3. Well, yes, for 32 bit images, plain white may be a bit strange to see, with all those gradients "youth like nowadays". And taking into account the tool is aimed at making small icons, it would be even less noticeable.

    4. That would be nice, and you could just default to white.

    BTW, nice work on your Windows Ribbon Library, I've been following your posts in the last days, but haven't got any chance to use it yet.

    להגיב
  4. Weight Conversion 2 ביולי 2011 ב 8:07

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

    להגיב
  5. Eugene Gore16 ביולי 2012 ב 22:29

    I tried convert2bmp.exe but I get 32bit images with altered background: white turns black. What do I do wrong?

    להגיב