DrawImage and set its alpha change in editor


#1

Hi again,
I have an image that i want to appear and disappear on button click.
I have this code in the editor constructor:

redLed = ImageCache::getFromMemory(BinaryData::redLed_png, BinaryData::redLed_pngSize);

And Iwant that it appears only when I click an ImageButton. I have its listener and this code:

if (button == &configBtn)
{
    config = processor.getConfig(selProgram);
    lcdText.setText(presets.configurations[config], dontSendNotification);
    redLed.multiplyAllAlphas(1);
    repaint();
}

But nothing happens…


#2

Well you’re always multiplying the alpha of the image by 1 in your button callback so it will stay the same. If you want it to appear/disappear, a better method might be to place your image in an ImageComponent and then call setVisible (true) or setVisible (false) in the button callback depending on whether you want it visible or not.

Ed


#3

Excuse me I have used alpha 1 but it would be 0…
And nothing happens.
I’m having troubles with ImageComponent anyway.
How do I use RectanglePlacemen?
(If you could make a n example plz)


#4

Sure, but if you’ve mutiplied your alpha channel by 0 once then multiplying by 1 will have no effect.

Use ImageComponent like you would any other Component - add it to your window using addAndMakeVisible() and give it a size using setBounds() - but also pass it the Image object you want it to display using the setImage() method. The RectanglePlacement argument is optional but just allows you to justify the image a certain way within the ImageComponent such as aligning it with an edge or stretching it to fit.

Ed


#5

Thanks, I’ve already done searching out in the JUCE APIs…
It works very well!
Thanks for the advice.