How to save screenshots?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Leandro

Greetings,

Apparently the Printscreen doesn’t send screencaptures to Windows clipboard (BTW, why?)… So, how can I take screenshots of my whole screen and save it as a file?

Thanks in advance.

… and what does this have to do with Godot exactly? Have you tried Google searching first?

SIsilicon | 2018-12-18 02:18

:bust_in_silhouette: Reply From: rojekabc

I think, this link may be helpful: https://forum.godotengine.org/12164/as-in-the-game-to-take-a-screenshot

Those answers are for Godot 2.0.

In Godot 3.0, you would do-

var image = get_viewport().get_texture().get_data()
image.save_png("path/to/save/screenshot.png")

SIsilicon | 2018-12-18 14:08

Thanks! It worked, but the screenshot is vertically flipped! :smiley:

if Input.is_key_pressed(KEY_PRINT):
	# start screen capture
	var image = get_viewport().get_texture().get_data()
	image.save_png("c:/lixo/screenshot.png")

Leandro | 2018-12-18 17:54

Add this line just before the save_as() function.

image.flip_y()

SIsilicon | 2018-12-18 18:20

if Input.is_key_pressed(KEY_PRINT):
	# start screen capture
	var image = get_viewport().get_texture().get_data()
	image.flip_y()
	image.save_png("c:/lixo/screenshot.png")

Believe it or not, now it stopped saving screenshots. When I press PrintScreen, the program stutters a little like before, which seems it’s saving the screenshot, but when I look inside it, there’s no screenshot. :frowning:

And before someone asks, yes, I have the permission for the folder and there’s no file in there that cannot be overwritten.

Leandro | 2018-12-18 20:12

Strange because it worked for me.

SIsilicon | 2018-12-18 23:33

Even stranger: it worked for me. After sometime it stopped working. I’ll check it out.

Thanks anyway!

P.S.: Found the problem. Apparently it did not work with Print Screen, but when I used another key it worked fine. Thanks again!

Leandro | 2018-12-19 00:29

Okay. Posted it as answer. Why don’tcha select my answer instead?

SIsilicon | 2018-12-19 02:03

:bust_in_silhouette: Reply From: SIsilicon

In Godot 3.0, you would do-

var image = get_viewport().get_texture().get_data()
image.flip_y()
image.save_png("path/to/save/screenshot.png")

Godot 4 update: use get_image

var image = get_viewport().get_texture().get_image()
image.save_png("path/to/save/screenshot.png")

(no need to flip y anymore as not using OpenGL currently; maybe later, if 4.1 supports OpenGL again and you use that, you may need to)

Hyper Sonic | 2022-11-06 17:46