Visual C++ 2005 won't load images from file Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
forrestcupp
Earned some good credits
Earned some good credits
Posts: 102
Joined: Thu Dec 28, 2006 5:12 pm
Location: Indiana, US

Visual C++ 2005 won't load images from file

Post by forrestcupp » Thu Nov 08, 2007 7:41 pm

I'm really getting annoyed with this problem. I'm using Visual C++ 2005 Express. Every time I try to load an icon or bitmap from a file, it won't allow it. It keeps telling me to check my resources. It seems as if it will only accept embedded media without allowing the loading of my media from the hard drive. I really don't want to have to add all of my content to my resources, and I can't even get that to work with a simple png file anyway.

Does anyone have any ideas on what I need to change so that I will be able to load image files?

User avatar
tierra
Site Admin
Site Admin
Posts: 1341
Joined: Sun Aug 29, 2004 7:14 pm
Location: Salt Lake City, Utah, USA
Contact:

Post by tierra » Thu Nov 08, 2007 7:52 pm

Yeah, you need to change the line of code that loads the image. There are several different ways of loading images, with shortcuts for each. The one you're using is meant only to be used with attached resources.

It'd help if you mentioned how you're loading the images if you expect help with this.

forrestcupp
Earned some good credits
Earned some good credits
Posts: 102
Joined: Thu Dec 28, 2006 5:12 pm
Location: Indiana, US

Post by forrestcupp » Thu Nov 08, 2007 7:54 pm

In my frame constructor, I have this:

wxString dir = wxGetCwd() + "\\exit.png";
wxBitmap quit(dir);


I also tried:

wxBitmap quit;
quit.LoadFile(dir);

Neither one worked.
I've tried using wxImage, which seems to allow me to load a file, but it keeps saying "No handler found for image type" no matter what type I use.

timg
Earned some good credits
Earned some good credits
Posts: 148
Joined: Mon Jan 23, 2006 6:52 pm

Post by timg » Thu Nov 08, 2007 8:17 pm

For the image handler issue, did you initialize the image handler for the type you want to use?

you could stick this:

Code: Select all

    ::wxInitAllImageHandlers();
into your wxApp::OnInit() function if you didn't.

forrestcupp
Earned some good credits
Earned some good credits
Posts: 102
Joined: Thu Dec 28, 2006 5:12 pm
Location: Indiana, US

Post by forrestcupp » Thu Nov 08, 2007 8:26 pm

Thank you. I didn't know to do that. I'm just starting to learn this and I'm going through the intermediate tutorial on making a toolbar. When I type the code how they have it, it doesn't work.

So I initialized all image handlers. Then I had to load the file into a wxImage and send that to a wxBitmap to use in the toolbar.

Thank you. I've found that the intermediate tutorials are more confusing than they need to be and they don't tell you everything you need to know. I wish there were a more complete tutorial somewhere that is easy to follow.

forrestcupp
Earned some good credits
Earned some good credits
Posts: 102
Joined: Thu Dec 28, 2006 5:12 pm
Location: Indiana, US

Post by forrestcupp » Thu Nov 08, 2007 8:44 pm

Well, I have another problem after I already marked it solved.

I can get the image into the toolbar even without converting it to a wxBitmap. But the image isn't shrunk to fit the toolbar. It only shows the upper right corner of the image. Do you know how to get it to be sized to the toolbar? It seems like that if I resize my image to fit my toolbar, it may not be right on another platform.

timg
Earned some good credits
Earned some good credits
Posts: 148
Joined: Mon Jan 23, 2006 6:52 pm

Post by timg » Thu Nov 08, 2007 9:17 pm

I have not used Toolbars, but I would think that you need to resize the image to the correct dimensions. If you are worried about resizing to the right size, call GetToolBitmapSize() on the toolbar and resize to the size it gives you.

The wxImage size can be changed with image.Rescale(width, height)

forrestcupp
Earned some good credits
Earned some good credits
Posts: 102
Joined: Thu Dec 28, 2006 5:12 pm
Location: Indiana, US

Post by forrestcupp » Thu Nov 08, 2007 9:45 pm

Thank you. The GetToolBitmapSize() function was exactly what I was looking for for portability. I've noticed that these toolbar icons are a lot bigger on some platforms than they are in Windows.

Post Reply