Displaying the background image on my app


#1

Hi, I am very much new to juce. So, sorry if the question is very obvious.

 

1) I want to display a background image on my application. Till now, I searched how to load image from my computer. I found only the links using the the filebrowser class. Since its a background image, I cannot use that class to select the image from the computer.

2)Also, is it possible to change the text in a component using a button listener?? I saw that if the text is in a label, we can change it. But is it possible to change the text written using drawtext in a component using a listener???

So, please help me with this.


#2

1) I am not 100% sure what you are after, but if you want to display a background image in your app, then you would add the image file to the binary resources of your app in Introjucer (add file to project, untick "Compile", tick "Add to binary resources"). Then in your code, you can construct an Image object from it using ImageCache::getFromMemory, and then you can draw that Image object in the paint() method of your component using Graphics::drawImage().

2) If you want text that changes on a button click, you can create a Label (make it not editable), make it a Listener of whatever you want to listen to (ButtonListener for example), and then add a buttonClicked callback where you can call setText on that label.

Check out this tutorial 

http://learn.juce.com/doc/tutorial_listeners_and_broadcasters.php

I wouldn't recommend it, but if you insist on using Graphics::drawText for generating your text, you can make the text a member variable String of your component, make the whole component a ButtonListener, then in the buttonClicked callback change the value of that String and then trigger a repaint() from there. This will repaint everything, so it may be less efficient.


#3

Hi,

 

Thanks for your reply.

 

Now, I loaded the image as part of my project. Its under "myproject\images\image.png". How to speccify it in the GetfromMemory function??

Image myImage(ImageCache::getFromMemory(<What to specify here??>));

Thanks in advance for your reply.

 

-Ranjith


#4

See my answer in this thread

http://www.juce.com/forum/topic/parameters-getfrommemory


#5

Hi, Thanks a lot for your reply