Jump to content
  • Advertisement
Sign in to follow this  

Displaying Images with Visual C++

This topic is 4061 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm writing a "Virtual Pet" program where you have a series of buttons that affect your virtual pet's attributes. For example, if you push the KICK PET button, your pet's happiness goes down by 5. As the pet's happiness changes, I want to display a picture (jpeg) that represents the pet's current mood. I have a series of 6 images I'd like to cycle through depending on the current happiness value. My Attempts Using Visual C++: I first tried using a pictureBox control with an imageList (loaded with the 6 jpegs). The program worked, but the images were severely distorted. I then tried using the Image::FromFile method. This also worked as intended, but since the images are not embedded in the code (the program must locate them on the hard drive) this program only works on my machine when my pictures are in the right location. Finally, I have converted a jpeg image into a .RES file (I assume this means the picture will be embedded in the compiled program), but I don't know how to access the file and display it in my pictureBox. Does anybody know how I can accomlish my goal? Any help would be greatly appreciated!

Share this post

Link to post
Share on other sites
You almost got it!
I got a slideshow program written in C++ that cycles through various images and I use LoadResource() to load the images that are in resource files.
I would post the code but I find C++ code so ugly nowadays after using Python all the time I can't get myself to post it.

Share this post

Link to post
Share on other sites
Original post by Mastaba
Instead of using Image::FromFile use Bitmap::FromResource.

Ok I found the code example from Microsoft on using Bitmap::FromResource. Here it is:

static Bitmap^ FromResource (
IntPtr hinstance,
String^ bitmapName


I'm using this command:
pictureBox1->Image = Bitmap::FromResource(IntPtr.Zero, "MyResourceName");

Program runs, but as soon as it tries to load the resource it quits with this error:

"An unhandled exception of type 'System.ArgumentException' occurred in System.Drawing.dll

Additional information: Parameter is not valid."

What am I doing wrong? What can I do to make this work?

[Edited by - n8hanson on May 8, 2007 1:46:09 PM]

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!