Fiiting Image into Rectangle

Hey all,

I have a magnitude spectrogram that I’ve computed and is stored in an Image object. I’m trying to draw that image into a Component object within my component, but the Image is larger than the Component. For instance, the Component is 1180x270px and the Image is 1382x1025px (the width of the Image is variable depending on the length of the input file). My problem is trying to scale the Image to fit inside the Component, as currently it’s only displaying a portion of it. Can JUCE do this automatically? Or do I have to write my own function for this?

Here’s the drawing code for my component:

void ImageLayer::paint(Graphics &g)
    // some scaling code here???

    g.drawImage(*image, 0, 0, getWidth(), getHeight(),
                 0, 0, image->getWidth(), image->getHeight());

Thanks ahead of time!

We have a whole bunch of utilities to do this - try the RectanglePlacement class.

slightly old topic, but to help someone else out:

g.drawImage( image, getLocalBounds().toFloat() );

this will draw your image stretched to fit the bounds of your containing component.

take a look at this method in the API:

void Graphics::drawImage	(	const Image & 	imageToDraw,
Rectangle< float > 	targetArea,
RectanglePlacement 	placementWithinTarget = RectanglePlacement::stretchToFit,
bool 	fillAlphaChannelWithCurrentBrush = false 
)		const
1 Like