[Godot 3] Capturing Viewport + resizing it + saving it to png
This past week I've been working on porting my project from Godot 2 to Godot 3 and I'm almost finished, but there's this small issue I can't seem to solve.
In my game, you can take screenshots by pressing a key. However, the game has a tiny resolution, so I'd like to be able to resize the screenshots before they are saved to the disk. In Godot 2 I could achieve this easily by using
capture.resized(width, height, interpolation), but for some reason I can't get
resize()) to work properly in Godot 3. This is the code:
# get data var img = get_viewport().get_texture().get_data() # wait two frames yield(get_tree(), "idle_frame") yield(get_tree(), "idle_frame") # flip img.flip_y() # get screen ratio + resize capture var ratio = load_config("screenshot_ratio") if ratio == null: ratio = 2 img.resize(img.get_width()*ratio,img.get_height()*ratio,0) # save to file img.save_png("screenshot.png")
I get no error output, and the picture saves alright if I don't resize it, but if I do, all I get is a blank image the same color as the viewport background.
I guess I'm missing something? I'd really appreciate any help!