I have also read it and it helped enormously.
The problem is in understanding the differences between a Windows executable and a MAC executable.
To explain the differences here is a practical example.
1. Create a folder 'Display Image' wherever you like to keep you PB programmes.
2. Create a sub folder in the display images folder called 'Resources'
3. Copy a jpg image of your choice to the Display Image/Resources folder. I used 550.jpg.
4. Start a new file with PB and copy the code below into the file.
Code: Select all
UseJPEGImageDecoder()
Global frmDisplayImage
Global imgDisplay
Global ImageFileName.s,ImageToDisplay.i
frmDisplayImage = OpenWindow(#PB_Any, 0, 0, 310, 330, "Display An Image", #PB_Window_SystemMenu)
imgDisplay = ImageGadget(#PB_Any, 20, 10, 270, 290, 0)
ImageFileName = "Resources/550.jpg"
ImageToDisplay = LoadImage(#PB_Any,ImageFileName)
SetGadgetState(imgDisplay,ImageID(ImageToDisplay))
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
5. Save the file as 'Display Image (01).pb
6. Change the ImageFileName in the code to the image you copied to the Resources folder.
7. Run the programme and your image will be displayed.
8. Compile the programme twice, the first time use Display Image(01).app, the second time use Display Image(01a).app.
This will leave you with two applications exactly the same just named differently.
Run each application and no image will be displayed!
Now to understand why no image?
Use Finder and right click on Image Display(01).app, select Show Package Contents and you should see the following:-
Display Image (01).app
├── Contents
│ ├── Info.plist
│ ├── MacOS
│ ├── DisplayImage(01) - - - - This is your executable
Notice that there is no Resources folder.
Again using Finder right click on Display Image (01a).app and you will see the same folder tree.
Now follow these steps:
1. Double click the 'Contents' folder it opens the folder.
2. Using finder create a new folder called 'Resources' in the contents folder.
3. Double click the new Resources folder.
4. Copy your image to this new resources folder
5. Step back to the Show package content display and it should look similar to this.
Display Image (01a).app
├── Contents
│ ├── Info.plist
│ ├── MacOS
│ ├── DisplayImage(01) - - - - This is your executable
│ ├── Resources
│ ├─── 550.jpg
6. Step back to your main folder and double click the Display Image (01a).app to run the application and the image is displayed.
The reason using ImageFileName = "Resources/550.jpg" fails when compiled in Display Image(01).app is that it looks for the Resources folder INSIDE the application which does not exist until you create it.
PB does provide another way to include images with an executable using a data section.
Create a new file with PB and copy the code below to this file as Display Image (02).pb, change the file name in the DataSection portion to your file name then run the application and the image is displayed.
Code: Select all
UseJPEGImageDecoder()
Global frmDisplayImage
Global imgDisplay
Global ImageFileName.s,ImageToDisplay.i
frmDisplayImage = OpenWindow(#PB_Any, 0, 0, 310, 330, "Display An Image", #PB_Window_SystemMenu)
imgDisplay = ImageGadget(#PB_Any, 20, 10, 270, 290, 0)
ImageToDisplay =CatchImage(#PB_Any, ?StartEnabled)
SetGadgetState(imgDisplay,ImageID(ImageToDisplay))
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
DataSection
StartEnabled:
IncludeBinary "Resources/550.jpg"
Compile this application and then run and the image is displayed without adding a resources folder.
Now a few considerations if like me your application displays many images, currently I have nearly 12Gb of images to display, including these in the application would bloat the application to 12Gb plus. This makes no sense as it would take forever to load and run.
Include just the images for your application, such as button images or small images used for icons etc. in the application. The images which are data can be placed elsewhere, such as in the users Documents folder and accessed easily from there.