1

I am using wxwidget on my Mac OSX and just cant make my app access my resources directoy within my app bundle.

I have a file name image.bmp in my resources folder and accessing it through :

    m_bitmap1 = new wxStaticBitmap( this, wxID_ANY, wxBitmap( wxT("Resources/image.bmp"), wxBITMAP_TYPE_ANY ), wxDefaultPosition, wxDefaultSize, 0 );

my app yell : "File not found error" on that file. I also tried ./Resource, or just image.bmp but nothing seems to work.

Looking into the app file I can see the file in there. but for some strange reason it seems to ignore it.

Any idea ?

jww
  • 97,681
  • 90
  • 411
  • 885
Nuno_147
  • 2,817
  • 5
  • 23
  • 36

1 Answers1

1

By default wxOSX will only load PNG and JPEG bitmaps from the resources, so I advise you to convert your bitmap to PNG and use wxBITMAP_TYPE_PNG_RESOURCE in the ctor. You also need to remove the explicit "Resources/" as the path is looked up under this directory of your bundle automatically. I.e. the recommended solution is to use wxBitmap("image.png", wxBITMAP_TYPE_PNG_RESOURCE).

Notice that this works under Windows too, provided you embed your PNG into the resources using RCDATA type as explained in wxBITMAP_PNG() documentation. For the other platforms you would need to embed it directly into the program code, this is also explained in the same link.

Otherwise, i.e. if you really want to use BMP, you need to use wxStandardPaths::GetResourcesDir() to construct the full path to your bitmap explicitly.

VZ.
  • 21,740
  • 3
  • 39
  • 42
  • I have tried that with PNG as well but it didn't work. I have also used the image sample in the wxWidget and seems they having the same problem. when I ran it , it worked , however I then noticed that on the same level as the .app file there is the cursor.png file (which the sample use) and I remove it and kept it only in the bundle resources directory, the app failed to run. so I assume that natively it just doesn't work. – Nuno_147 Sep 22 '14 at 08:20
  • I forgot that you needed to explicitly use `wxBITMAP_TYPE_PNG_RESOURCE`, I've updated my answer to mention it. – VZ. Sep 22 '14 at 12:23
  • What will happen when I'll do that on a windows environment ? My app is Multi platform. – Nuno_147 Sep 22 '14 at 15:40