Solved

The format of the bitmap is not supported

Posted on 2006-07-02
8
350 Views
Last Modified: 2013-12-03
Hi,

I have a 256 color bitmap image that's 14 X 14 pixels in size.  I used the following code to write a number between 1 and 99, and save it, to create 99 versions of the bitmap.  The images get created and look fine.  But when I call the following line, I get an exception.  It works fine for the stock image file (blank dot) which I use as a base.  But when any image I created is used, it throws an exception.

symbol = mpControl.ActiveMap.Symbols.Add( fileName );


Exception: "The format of the bitmap is not supported.  Bitmaps must be compressed and use 1, 4, 8 or 24 bit color."

What can I do differently to so that the 99 images I create will appear no different from the stock image?

Thanks,
Bob


for ( int number=1; number<=99; number++ )
{
string breadCrumbFileName = Preferences.ImagesDir + colorName + number.ToString() + ".bmp";
if ( handles.Utils.FileExists( fileName ) )
{
      Image outputImg = Image.FromFile(fileName);
      Bitmap outputBmp = new Bitmap(outputImg);
      Graphics g = Graphics.FromImage(outputBmp);

      // do something with "g"
      Font arial            = new Font( "Arial", 7 );
      Font arialBold      = new Font( arial, FontStyle.Bold );

      if ( number < 10 )
      {
            g.DrawString(number.ToString(), arialBold, Brushes.White, new PointF(3,1));
      }
      else
      {
            g.DrawString(number.ToString(), arialBold, Brushes.White, new PointF(0,1));
      }

      // release the graphics
      g.Dispose();

      // save the changes in the original fileName
      outputBmp.Save( breadCrumbFileName, System.Drawing.Imaging.ImageFormat.Bmp);
}

0
Comment
Question by:ba272
  • 5
  • 3
8 Comments
 

Author Comment

by:ba272
ID: 17028653
I suspect the problem involves the bit depth.  My prior raised that question.  But I don't know how to check that ot set that.
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 500 total points
ID: 17029092
Try to replace last line with the following code:

// save the changes in the original fileName
//     outputBmp.Save( breadCrumbFileName, System.Drawing.Imaging.ImageFormat.Bmp);

Bitmap output24 = new Bitmap(outputBmp.Width, outputBmp.Height, PixelFormat.Format24bppRgb);
g = Graphics.FromImage(output24);
g.DrawImage(outputBmp, 0, 0);
g.Dispose();

output24.Save( breadCrumbFileName, System.Drawing.Imaging.ImageFormat.Bmp);

This code converts bitmap to 24 bpp format. Accorfing to error message, this must solve the problem.
0
 

Author Comment

by:ba272
ID: 17042458
Alex,

I am having trouble compiling.  PixelFormat could not be found.  I am using VS 2003.  What namespace is that?  WMEncoderLib does not work.

Bob
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 48

Expert Comment

by:AlexFM
ID: 17042752
System.Drawing.Imaging Namespace
0
 

Author Comment

by:ba272
ID: 17043050
Thanks.  It works.  But that presented a new problem.

I write the digits as white, but apparently it's transparent, because many are hard to read because of there they end up on a map.

Any idea how to make this non-transparent?


Thanks,
Bob
0
 

Author Comment

by:ba272
ID: 17043106
I'd like the text I am writing in the circle and the circle to be non-transparent.  But I'd like the four corners to be transparent.
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 17043144
I don't know what are requirements of the control you are working with, maybe there is transparent color property, which is set to white.
0
 

Author Comment

by:ba272
ID: 17044041
that's okay.  You got me over the big hump.

Bob
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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…

820 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