code for displaying picture on MAC 0S 10 Topic is solved

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
Rabah
Earned some good credits
Earned some good credits
Posts: 133
Joined: Fri Jun 08, 2007 8:21 am

code for displaying picture on MAC 0S 10

Post by Rabah »

Dears,

I am coded on windows and I have to use my code on Mac Os 10. I am very new with this OS. I use Xcode.

I managed to build my project using the wxwidgets libraries but the picture are not displayed. I created a directory resouce in the project in xcode and modify the path for the picture but nothing.

My question is general : how must I organize my project for the picture and resource for a release version? And are there specific code to display picture?

Regards,

Rabah
benedicte
wxWorld Domination!
wxWorld Domination!
Posts: 1409
Joined: Wed Jan 19, 2005 3:44 pm
Location: Paris, France

Post by benedicte »

wxWidgets being a cross-platform environment, I don't think there should be specific code to write on Mac...

Did you build the "image" sample on Windows/Mac and play with it to see if it works? You can also modify it to load your image(s).
Rabah
Earned some good credits
Earned some good credits
Posts: 133
Joined: Fri Jun 08, 2007 8:21 am

Post by Rabah »

Yes In fact, but

first Item
In windows if you include a picture whch is not in resource you code :

Code: Select all

wxBitmap pic
pic.LoadFile("picture.png,type)
and windows load automatically the picture if it is in the same path of the source file (in the project)

This does not work on MAC (correct me if I am wrong)

second item
Wanting to put my picture in my project as resource for example a release version. Are there differents ways for windows (visual studion) and Mac 0S 10 (xcode)?

regards

Rabah
DimX
Earned a small fee
Earned a small fee
Posts: 20
Joined: Sun Jul 15, 2007 1:08 pm
Location: Estonia

Post by DimX »

Rabah wrote:windows load automatically the picture if it is in the same path of the source file (in the project)
Not the path where the source file is, but the current working directory, which is probably set by your IDE when it launches the program.
wxFileName::GetCwd
wxFileName::SetCwd
benedicte
wxWorld Domination!
wxWorld Domination!
Posts: 1409
Joined: Wed Jan 19, 2005 3:44 pm
Location: Paris, France

Post by benedicte »

Rabah wrote:Yes In fact, but

first Item
In windows if you include a picture whch is not in resource you code :

Code: Select all

wxBitmap pic
pic.LoadFile("picture.png,type)
and windows load automatically the picture if it is in the same path of the source file (in the project)
That's the way it works, it is globally design this way on most systems. The loaded files (not specifically pictures, nor program resources) are looked into the directories that appear in the PATH environment variable, then the "current" directory, ie the one you launch the app from.
Rabah wrote: This does not work on MAC (correct me if I am wrong)
It should work the same way on MacOS.
Rabah wrote: second item
Wanting to put my picture in my project as resource for example a release version. Are there differents ways for windows (visual studion) and Mac 0S 10 (xcode)?

regards

Rabah
You shouldn't put your image in the resources. Just copy it near the app executable, or near the sources and use a relative path (../my_image.ext) to load it.
Rabah
Earned some good credits
Earned some good credits
Posts: 133
Joined: Fri Jun 08, 2007 8:21 am

Post by Rabah »

Ok thanks a lot for your response.

If I undetstood, or a release version I deliver the appa and the picture and not the app including all the picture?

Regards

Rabah
Rabah
Earned some good credits
Earned some good credits
Posts: 133
Joined: Fri Jun 08, 2007 8:21 am

Post by Rabah »

Dears,

On this picture you can see that I include my picture with the path and on the right the file "Resources" exists but the built step failed there are not the pictures.

Rabah
Attachments
code.png
benedicte
wxWorld Domination!
wxWorld Domination!
Posts: 1409
Joined: Wed Jan 19, 2005 3:44 pm
Location: Paris, France

Post by benedicte »

Please note that "Resources/hourglass.ani" means your working directory is CrossPassword.

I usually do not use any relative path in my apps because I don't know if the user will call it the proper way to have a coherent working directory.
I always build an absolute path using the executable directory (which I compose with a relative path to my resources)...

For example:
my_project
* include (*.h)
* src (*.cpp)
* resources (images, XRC, ...)
* output (debug/release, object files)
* .exe file

Code: Select all

file_path = get_executable_directory() + wxT("resources/my_image.png");
And when I deliver my app, the resources directory is near the executable.
Thus, whatever the working directory the user used, the file can always be loaded.[/quote]
Rabah
Earned some good credits
Earned some good credits
Posts: 133
Joined: Fri Jun 08, 2007 8:21 am

Post by Rabah »

Dear all. Benedicte thanks for responding,
I tried the following code but it does not function

[quote]wxString filepath = wxFileName::GetCwd(wxT("/Users/societyX/Desktop/CrossPassword/CrossPassword/Resources/"));
...
anim_panlist->LoadFile(filepath + wxT("hourglass.ani"),wxANIMATION_TYPE_ANY);
anim_panlist->Play();
...
/////////////////////Chargement des ic
benedicte
wxWorld Domination!
wxWorld Domination!
Posts: 1409
Joined: Wed Jan 19, 2005 3:44 pm
Location: Paris, France

Post by benedicte »

I wonder if you have called ::wxInitAllImageHandlers() in your app startup...
Rabah
Earned some good credits
Earned some good credits
Posts: 133
Joined: Fri Jun 08, 2007 8:21 am

Post by Rabah »

Yes I call it in the Init.cpp. This file instanciate the frame in which picture are called.
bool MyApp::OnInit()
{
wxInitAllImageHandlers();

FrameWizard * framewiz = new FrameWizard(NULL,-1,
GetString(IDS_TITLE_FRAME),
wxPoint(300,300),
wxSize(610,375),0|
wxDEFAULT_FRAME_STYLE);
framewiz->Show(true);
framewiz->SetFont(wxFont(10, wxSWISS , wxNORMAL, wxNORMAL, false,wxT("futura")));
SetTopWindow(framewiz);
return TRUE;
}
what other kind of problem it could be? I am On Mac the widget appear and a dialog Box say it is no possible to idsplay he picture as you can see on the picture below

regards


Rabah
Attachments
widget.png
Last edited by Rabah on Fri Jul 20, 2007 6:56 am, edited 1 time in total.
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

OS X uses app bundles, inside the app bundle there is a folder called 'ressources'. put your image there, then you can load the image at path 'wxStandardPaths::Get().GetResourcesDir() + wxT("/myfile.png")'

if you add the files to the project XCode will do it for you i think.

this is clean and also all files are inside the app so it's great for release versions, also GetResourcesDir() should work on all systems

---

"no bitmap handler for type 15" means there is no handler for a certain type of files... that means either it is not loaded either there is none. are you loading only PNG files or some other weird formats (e.g. wxBITMAP_TYPE_BMP_RESOURCE) ? i definitely load pngs on my mac... i'm not sure what 'type 15' is, i don't know where it's hidden in headres and can't find in docs

---

Also in the code you posted i see you use backslashes (\) for path seperator.,.. this is windows-only, on mac it is forward-slash (/)
Rabah
Earned some good credits
Earned some good credits
Posts: 133
Joined: Fri Jun 08, 2007 8:21 am

Post by Rabah »

Dear,
Auria wrote:OS X uses app bundles, inside the app bundle there is a folder called 'ressources'. put your image there, then you can load the image at path 'wxStandardPaths::Get().GetResourcesDir() + wxT("/myfile.png")'
I have forgotten to put (/) slash before the file like wxT("/myfile.png"). So at this time it works :-) :-). Tnaks to all of you.

Putting the path is Ok because without it does not function but as a cross application putting the path can create problem. is there a "cross" method or wxwidget function for this?

Regards

Rabah
mc2r
wxWorld Domination!
wxWorld Domination!
Posts: 1195
Joined: Thu Feb 22, 2007 4:47 pm
Location: Denver, Co
Contact:

Post by mc2r »

Rabah wrote:Putting the path is Ok because without it does not function but as a cross application putting the path can create problem. is there a "cross" method or wxwidget function for this?
wxFileName::GetPathSeparator might be what you are looking for.

http://www.wxwidgets.org/manuals/stable ... hseparator

-Max
Post Reply