Correct way to use File class with absolute paths

Hello, I’m very new to JUCE and am trying to use File to load up a splashscreen for a school JUCE project. I’ve used this code, which works:

File::getCurrentWorkingDirectory().getChildFile (“splashScreen.png”)

Only problem is that I have to put splashScreen.png in the build -> debug folder instead of in a source images folder. I’ve done this, which also works:

File::getCurrentWorkingDirectory().getParentDirectory().getParentDirectory().getParentDirectory().getChildFile ("…/SourceImages/splashScreen.png")

But it doesn’t feel entirely safe to me, as in I’m not sure if when I submit it and my lecturer tries the app on his own machine if the file path will be correct. Maybe I have done it right, but it’s hard to test!

Why don’t you just embed your image as a binary resource? Just drop it in the Projucer’s File Explorer section and activate it as Binary Resource (should be activated automatically normally).

You can then load it into an image through ImageCache::getFromMemory and then probably just use it as you already do.

Now the image is part of the binary, so you don’t have to care where your lecturer places that extra file - you just have to distribute the binary.

2 Likes