BMP files not working with Graphics object?

I have uploaded the problem source code at:

http://www.robotzgame.com/junk/robotz.zip



It would be nice if I could get it to work with BMP files instead of having to go back to using JPG.


Whenever I try and run the application I get the following error:

Additional information: A Graphics object cannot be created from an image that has an indexed pixel format.



===================================
ERROR DUMP:

'DefaultDomain': Loaded 'c:\winnt\microsoft.net\framework\v1.0.3705\mscorlib.dll', No symbols loaded.
'WindowsApplication1': Loaded 'C:\Documents and Settings\tom\Desktop\RobotzBest\bin\Debug\WindowsApplication1.exe', Symbols loaded.
'WindowsApplication1.exe': Loaded 'c:\winnt\assembly\gac\system.windows.forms\1.0.3300.0__b77a5c561934e089\system.windows.forms.dll', No symbols loaded.
'WindowsApplication1.exe': Loaded 'c:\winnt\assembly\gac\system\1.0.3300.0__b77a5c561934e089\system.dll', No symbols loaded.
'WindowsApplication1.exe': Loaded 'c:\winnt\assembly\gac\system.drawing\1.0.3300.0__b03f5f7f11d50a3a\system.drawing.dll', No symbols loaded.
'WindowsApplication1.exe': Loaded 'c:\winnt\assembly\gac\accessibility\1.0.3300.0__b03f5f7f11d50a3a\accessibility.dll', No symbols loaded.
An unhandled exception of type 'System.Exception' occurred in system.drawing.dll

Additional information: A Graphics object cannot be created from an image that has an indexed pixel format.


Unhandled Exception: System.Exception: A Graphics object cannot be created from an image that has an indexed pixel format.
   at System.Drawing.Graphics.FromImage(Image image)
   at Robotz.GameBoard.DrawPicture() in c:\documents and settings\tom\desktop\robotzbest\gameboard.cs:line 70
   at Robotz.GameBoard..ctor(PictureBox pBox, String resBoardName, ImageList iList) in c:\documents and settings\tom\desktop\robotzbest\gameboard.cs:line 60
   at Robotz.FormMainScreen.Form1_Activated(Object sender, EventArgs e) in c:\documents and settings\tom\desktop\robotzbest\formmainscreen.cs:line 103
   at System.Windows.Forms.Form.OnActivated(EventArgs e)
   at System.Windows.Forms.Form.set_Active(Boolean value)
   at System.Windows.Forms.Form.WmActivate(Message& m)
   at System.Windows.Forms.Form.WndProc(Message& m)
   at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.SafeNativeMethods.ShowWindow(IntPtr hWnd, Int32 nCmdShow)
   at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
   at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
   at System.Windows.Forms.Control.set_Visible(Boolean value)
   at System.Windows.Forms.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.Run(Form mainForm)
   at Robotz.FormMainScreen.Main() in c:\documents and settings\tom\desktop\robotzbest\formmainscreen.cs:line 96The program '[504] WindowsApplication1.exe' has exited with code 0 (0x0).


LVL 5
Tom KnowltonWeb developerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mohammed NasmanSoftware DeveloperCommented:
Hello

  Try to add new bitmap that has more colors (indexed colors are 8bit or less)


      Bitmap b = new Bitmap("board.bmp");
      //this will gave you the same error
      //Graphics g = Graphics.FromImage(b);
      // use this to solve the problem
      Bitmap b2 = new Bitmap(b.Width,b.Height,System.Drawing.Imaging.PixelFormat.Format16bppRgb555);
      Graphics g = Graphics.FromImage(b2);

HTH

Regards,
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Tom KnowltonWeb developerAuthor Commented:
Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.