Archive 17/01/2023.

[SOLVED] Taking screenshots

Mike

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.

Azalrion

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);

Graphics::TakeScreenShot(Image&)
Image::SavePNG(String&)

Mike

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 :stuck_out_tongue:

JTippetts

It’s something I’ve been meaning to do for awhile, but this thread reminded me. :smiley: 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.

Mike

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’

cadaver

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

Xardas

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?

cadaver

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

Azalrion

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.

cadaver

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

Xardas

Yes, that would be great!