Loading an image from a relative path


#1

Hello there JUCE people.

I basically am writing my first big app using JUCE and am wondering the best practice for custom background images and stuff?

My thinking is to bundle in some images into my source folder and use their relative path everywhere I want to load them into an Image object but I am not sure how to go about obtaining relative paths (or what they need to be relative to) or even if it is the best way to do it.

Currently the images are in PNG format so I assume i need a PNGImageFormat object to load the file into? Has anyone done this or anything similar and am I thinking along the right lines?


#2

Why not just include them as binaries via IntroJucer?


#3

Sounds sensible. Didn’t know you could do that, will check it out. Thanks!


#4

If it helps, check out the FriendlyBinaryBuilder project in my signature.


#5

I tried to build it but I got some weird clang error? I guess I am missing something I need to compile it but I have no idea?

I managed to include the image I want as a binary using the introjucer, but I am not seeing how I can load it to an image object without just using its path? Or am I supposed to just be using its normal path in the source and the compiler uses the binary when I build it? I have no idea


#6

Hm… Sorry, don’t know much about clang (don’t have a mac or linux box…). Possible that you just need to recreate the project for your IDE using the Introjucer…

The Introjucer has an example; find the file “jucer_AppearanceSettings.cpp”, line 675.

        const Image original (ImageCache::getFromMemory (BinaryData::background_tile_png,
                                                         BinaryData::background_tile_pngSize));