3 Replies - 1828 Views - Last Post: 02 June 2010 - 04:20 PM Rate Topic: -----

#1 Arctic0ne  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 27-March 10

DrawImage error

Posted 02 June 2010 - 04:01 PM

I am making a Paintball program for my Summer project in CS, I already have a lot invested into the project and decided to swap out the generic circles I had to label your lives with some 8-bit hearts I made in PS (It is a .PNG file if that makes any difference). I tried to implement into my program and came up with an error.

int livesX = 50;
            System.Drawing.Image Heart;
            Heart = Paintball.Properties.Resources.Heart;
            e.Graphics.FillRectangle(Brushes.Black, 0, 0, 794, 30);
            e.Graphics.DrawString("LIVES", new Font("Arial", 10, FontStyle.Bold), Brushes.White, 7, 7);
            if (lives == 3)
            {
                for (int numLives = 0; numLives < lives; numLives++)
                {
                    e.Graphics.DrawImage(Heart, livesX, 7, 14, 14);
                    livesX += 15;
                }
            }


************** Exception Text **************
System.ArgumentNullException: Value cannot be null.
Parameter name: image
   at System.Drawing.Graphics.DrawImage(Image image, Int32 x, Int32 y, Int32 width, Int32 height)
   at Paintball.Game.picGame_Paint(Object sender, PaintEventArgs e) in D:\Users\Kevin\Documents\visual studio 2010\Projects\Paintball\Paintball\Game.cs:line 73
   at System.Windows.Forms.PictureBox.OnPaint(PaintEventArgs pe)
   at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)
   at System.Windows.Forms.Control.WmPaint(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativewindow.WndProc(Message& m)
   at System.Windows.Forms.Nativewindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


Thanks in advance :bigsmile:

Is This A Good Question/Topic? 0
  • +

Replies To: DrawImage error

#2 elbielefeld  Icon User is offline

  • D.I.C Head

Reputation: 70
  • View blog
  • Posts: 216
  • Joined: 18-May 10

Re: DrawImage error

Posted 02 June 2010 - 04:10 PM

Maybe Heart is null? :)
Was This Post Helpful? 0
  • +
  • -

#3 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5436
  • View blog
  • Posts: 11,656
  • Joined: 02-June 10

Re: DrawImage error

Posted 02 June 2010 - 04:11 PM

Quote

System.Drawing.Image Heart;
You made an image variable called Heart, but never gave it an assignment.
Don't do it in two lines...

Image Heart = Paintball.Properties.Resources.Heart;

This post has been edited by tlhIn'toq: 02 June 2010 - 04:14 PM

Was This Post Helpful? 1
  • +
  • -

#4 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5436
  • View blog
  • Posts: 11,656
  • Joined: 02-June 10

Re: DrawImage error

Posted 02 June 2010 - 04:20 PM

Have you put a breakpoint at this line
int livesX = 50;

Then walked through the code line by line to confirm your variable is being assigned a value?

At this point it would be null
System.Drawing.Image Heart;

But after assignment of your resource you should see it's value change (in the Autos or Locals pallet)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1