[Solved] createComponentSnapshot at smaller scale?

Hi,

I want to create a snapshot of my application. I saw that I can call “Component:: createComponentSnapshot()” on my main component. The thing is: I want the snapshot to be at a much smaller size than my actual component size. My component is displayed in full-screen. But the snapshot should only be 200x200 pixels and still contain the entire component.
I want a small snapshot, because taking a snapshot in full-screen resolution does take quite a lot of time. Which is a noticeable delay in the UI.

I saw that createComponentSnapshot has a “scaleFactor”. But it does not seem to scale down the component. Rather is scales down the grabbed area. It seems. Or mabye I am using it wrongly?

I could of course call a “setBounds(smallerBounds)” on my main component, befor taking the snapshot. But that causes flicker, because the component actually resizes, which is visible.

Or maybe there is a way to call setBounds() without triggering a repaint of the component nor of any of its children? That would help too, I think.

You can scale the Image you’re getting from createComponentSnapshot(). See Image::rescaled()

Hi Achder,

Thanks for you answer. But then I still have to take a snapshot in full screen resolution first.
Taking that snapshot creates a short lag in the GUI. Because a lot of components have to be repainted at a large resolution, I assume. I do not like this lag. Therefore I would like to take the snapshot at a small resolution, which should eleminate the lag.

I can’t really see how this would be possible. Maybe you should do something like create an image of your window with the native image capture instead? It won’t have to repaint the JUCE classes then.
See Image createSnapshotOfNativeWindow (void* nativeWindowHandle);
(It’s an internal JUCE function so won’t be in the public docs)

Hi Dave, thanks for the suggestion.
This seems to be a native Windows function?

And I just got another idea:
Is it possible to “grab” the image, which JUCE sends to the graphic card?
If yes, then I would not need to createComponentSnapshot(). Instead I could just copy the buffer, which JUCE is sending to the screen anyways.
Hmm…

Suppose you want your Image to be a thumbnail a 1/4 of the original component c, doesn’t

Image thumbnail = c.createSnapshot (c.getLocalBounds () / 4, false, 0.25f)

do the job?

If not, then there’s probably something wrong with its implementation

Thanks Yfede,

You were right. My bad. The scaleFactor is actually working.
Not sure why I did not get it to work the first time.

Here is what you can write in order to get a thumbnail with 1/4 size:
thumbnail= createComponentSnapshot(Rectangle<int>(0, 0, getWidth(),getHeight()), false, 0.25);

Thanks everyone!
Sorry for creating confusion.

You can obtain that same Rectangle that you are passing, with a single call to getLocalBounds(). it’s more readable

1 Like