code for displaying picture on MAC 0S 10 Topic is solved
code for displaying picture on MAC 0S 10
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
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
Yes In fact, but
first Item
In windows if you include a picture whch is not in resource you code :
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
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)
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
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.Rabah wrote:windows load automatically the picture if it is in the same path of the source file (in the project)
wxFileName::GetCwd
wxFileName::SetCwd
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:Yes In fact, but
first Item
In windows if you include a picture whch is not in resource you code :and windows load automatically the picture if it is in the same path of the source file (in the project)Code: Select all
wxBitmap pic pic.LoadFile("picture.png,type)
It should work the same way on MacOS.Rabah wrote: This does not work on MAC (correct me if I am wrong)
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 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
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
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]
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");
Thus, whatever the working directory the user used, the file can always be loaded.[/quote]
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
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
I wonder if you have called ::wxInitAllImageHandlers() in your app startup...
Yes I call it in the Init.cpp. This file instanciate the frame in which picture are called.
regards
Rabah
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 belowbool 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;
}
regards
Rabah
Last edited by Rabah on Fri Jul 20, 2007 6:56 am, edited 1 time in total.
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 (/)
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 (/)
Dear,
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
I have forgotten to put (/) slash before the file like wxT("/myfile.png"). So at this time it works . Tnaks to all of you.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")'
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
wxFileName::GetPathSeparator might be what you are looking for.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?
http://www.wxwidgets.org/manuals/stable ... hseparator
-Max