"Can't load bitmap from resources" Error 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.
User avatar
ColleenKobe
Earned some good credits
Earned some good credits
Posts: 109
Joined: Mon Aug 31, 2015 3:47 pm

Re: "Can't load bitmap from resources" Error

Post by ColleenKobe »

doublemax, here you go!
Main_L2.7z
Contains most of the files needed for Colleen Kobe's "Level_2_Test" workspace and project.
(54 KiB) Downloaded 112 times
If there is something missing--like the definition of the SetBitmap() method, which I couldn't find but maybe I just missed it--let me know and I'll look elsewhere. Or if the file doesn't unzip properly, perhaps I can attach a flurry of files, instead of just one.
User avatar
doublemax
Moderator
Moderator
Posts: 19102
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: "Can't load bitmap from resources" Error

Post by doublemax »

Just WOW!

I really couldn't believe it, but the compiler actually created code to implicitly convert a wxString to wxBitmap using one of the wxBitmap constructors. But as this constructor has wxBITMAP_TYPE_BMP_RESOURCE as default for "type", loading of the bitmap fails.

To circumvent that, you have to rewrite the code a bit:

Code: Select all

wxString bmp_name;

if (label == lbl_A)
    bmp_name = bmp_A;
else if (label == lbl_B)
    bmp_name = bmp_B;
else if (label == lbl_E)
    bmp_name = bmp_E;
else if (label == lbl_H)
    bmp_name = bmp_H;
else if (label == lbl_Q)
    bmp_name = bmp_Q;
else if (label == lbl_S)
    bmp_name = bmp_S;

if ( !bmp_name.IsEmpty() ) 
{
	wxBitmap bmp( bmp_name, wxBITMAP_TYPE_ANY);
	if ( bmp.IsOk() )
		Desired_Picture->SetBitmap(bmp);

	Layout();
}
Now switching the bitmap works, but there will be some redraw errors because the bitmaps have different sizes. I'll leave fixing that for another thread ;)
Use the source, Luke!
User avatar
ColleenKobe
Earned some good credits
Earned some good credits
Posts: 109
Joined: Mon Aug 31, 2015 3:47 pm

Re: "Can't load bitmap from resources" Error

Post by ColleenKobe »

Thank you, doublemax! You're brilliant! You got rid of that error message for me. Thank you!

I will tackle the new errors, and if I can't fix them myself, I'll post again.

Best of wishes to you!
Colleen
User avatar
ColleenKobe
Earned some good credits
Earned some good credits
Posts: 109
Joined: Mon Aug 31, 2015 3:47 pm

Re: "Can't load bitmap from resources" Error

Post by ColleenKobe »

Just for the record...I fixed the last two problems by just copying the graphics files into the same directory as the executable.

doublemax was right about the pictures drawing a little funky because the images are different sizes, but that's easily fixed, and anyway this was just a test program to create wxWidgets controls. All is well. Thank you all!
Post Reply