How do I go about to change the background of the JUCE Application with an image?

Hi, I would like enquire how can I go about to change the background image of the application?


Here is where the image going to be located(image not yet placed inside).

What codes should be modify and which header/ccp file?


You should be able to load the image using
juce::Image background = juce::ImageFileFormat::loadImage (BinaryData::<nameOfResource>, BinaryData::<nameOfResource>Size)

then you can draw it in your paint function using:

g.drawImageWithin (background, getLocalBounds(), juce::RectanglePlacement::stretchToFit)

(provided the image is the same aspect ratio as the application window)
Hope this helps.

Or, derive from ImageComponent instead of Component.

1 Like

is the paint function a existing function? If not, where shall the function go to?

Look at the documentation for the Component class. Component::paint () is a virtual function that you can override.

Or, as I indicated, you can change the base class from Component to ImageComponent, for MainComponent, or DeckGUI, which ever is the component you want to have the image background for.

Thank you for your help!

The basic code should be working fine but currently I have this problem.

backgroundImage = ImageCache::getFromMemory(BinaryData::background_png,BinaryData::backgroundSize);

The error is “BinaryData” has no such member of “Background_png”.

I am wondering if you able to help with this? Thanks

Add the image file to the project in Projucer and resave the project.