Writing to a bimap and saving it, makes it unusable

Posted on 2006-05-09
Last Modified: 2013-12-03

I start with a bitmap which is readable by MapPoint.  The variable name of the bitmap (defined earlier) is called "fileName".  Then I write the digit "1" on it, and save the file.  The subsequent bitmap can not be added to a MapPoint symbol's list.  It produces the following exception:

"The format of this bitmap is not supported.  Bitmaps must be uncompressed and use 1, 4, 8 or 24 bit color".

Can anyone see in my code what I am doing wrong?


Image img = Image.FromFile(fileName);
Bitmap bmp = new Bitmap(img);
// get a graphics so we can draw
Graphics g = Graphics.FromImage(bmp2);
Font arial            = new Font( "Arial", 7 );
Font arialBold      = new Font( arial, FontStyle.Bold );

g.DrawString("1", arialBold, Brushes.White, new PointF(3,1));

// release the graphics

// save the changes in the original fileName
bmp.Save( "newVersion.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
Question by:ba272
    LVL 12

    Assisted Solution

    If you create an Image first, then a bitmapfrom this image, the 'Bit Depth' for the bmp object will be 32 bit (check 'PixelFormat' property). Try creating the bitmap directly from the fileName:

    Bitmap bmp = new Bitmap(fileName);
    Graphics g = Graphics.FromImage(bmp);

    Author Comment

    No, that didn't work. But I think I found a symptom of the problem.  When I drag and drop the non-working bitmap into VS 2003, I get an error.  It says it can't open the bitmap because there are greater that 256 colors.  So I presume my use of Brushes.White is the problem.

    Any idea how to get around this?

    LVL 85

    Accepted Solution

    You can specify the PixelFormat of the Bitmap when you create it, but you then can't start with the Image in it:

    After creating the Bitmap and getting a Graphics for it, you can draw the original image into it using the Graphics.DrawImage() function:
    LVL 12

    Assisted Solution


    When you create a bitmap giving the file name of .bmp file as parameter, the new created image will have the same color depth. So if the new image has more than 256 color this means that the original bitmap has more than 256 colors too.
     256 colors correspond to 8 Bit Depth, and a value of 'Format8bppIndexed' for PixelFormat property. (as a note, you will cannot create Graphics object from this kind of bitmap).

    VS2003 should open bitmap files even with they have more than 256 colors. You say that the original can be opened and the new one can't?

    Author Comment

    Okay.  So now it seems THE question is how do I create the new bitmap.  I'll be drawing the original image into the new bitmap once it's created.  But which of 12 constructors do I use when I create it?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Suggested Solutions

    Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now