I’d like to implement the take screenshots feature.
From previous discussion forum I’ve found that there are TakeScreenShot and SavePNG functions, but I didn’t find the way to use them.
[SOLVED] Taking screenshots


Its pretty simple, the docs are useful for working things out for functions like these.
Image screenshot(context_);
GetSubsystem<Graphics>()->TakeScreenShot(screenshot);
screenshot->SavePNG(path/to/dest/file.png);

Thanks for reply, I’m still missing something, I can’t get it to work in script.
EDIT: many thanks to JTippetts for exposing Image constructor to lua

It’s something I’ve been meaning to do for awhile, but this thread reminded me.
I use a custom executable and until this change, I have been taking screenshots inside the .exe in response to a custom event. Having Image exposed to Lua makes it so much easier.

Everything works fine for script (angel and lua).
But for C++, I get this error for screenshot->SavePNG(…):
error: base operand of ‘->’ has non-pointer type ‘Urho3D::Image’

When the image is a locally constructed object instead of pointer to image, you need to use . instead of ->

When I try to resize the image before saving it, the image file it produces is screwed up (grey image).
screenshot.SetSize(160, 90, screenshot.GetComponents());
Am I missing something?

SetSize() destroys the existing data. There is currently no function to arbitrarily resample an image to a new size.

If anyone would like the functionality we have a bilinear interpolating and nearest-neighbour scaling function we added as a utility but could fold into the image class.

I’m sure that would be appreciated, and should fit well into the Image class.

Yes, that would be great!