Can't save PNG at path!

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

I have a painting game, I want to save the player’s painting/viewport as a png.
Here’s my code:

func save_painting():
    var masterpiece = get_viewport().get_texture().get_data()
	
	masterpiece.flip_y()
	masterpiece.convert(Image.FORMAT_RGBA8)
	
	var save_path = "res://Minigames/paint/input/Masterpiece.png"

	masterpiece.save_png(save_path)

But I keep getting this error log:

ERROR: Can't save PNG at path: 'res://Minigames/paint/input/Masterpiece.png'. at: save_image (drivers/png/resource_saver_png.cpp:56) - Condition "err" is true. Returned: err

It works ok in Godot but once exported it causes a crash. Tried for days to solve this myself to no avail. Please help!

Thank you!

Do you have write permission to said location? Try running the exported game as administrator and see if that makes any difference.

Ninfur | 2022-06-17 14:35

:bust_in_silhouette: Reply From: Inces

“res” folder only exists for a project. You need custom folder after exporting, the one that every user has. Usually it is user/appdata, but You can pick any real system path

Thank you, I saved it at path user://masterpiece.png. It saves, and appears in the file manager, but when I try to load it as sprite texture in godot it gives this error message:

ERROR: Resource file not found: user://masterpiece.png.
   at: _load (core/io/resource_loader.cpp:275) - Condition "!file_check->file_exists(p_path)" is true. Returned: RES()

This is how i load it in godot:

$Sprite.texture = load("user://masterpiece.png")

Wracked my brain for days. Still confused.

Might you know why this error appears?

amberlimshin | 2022-06-22 10:02

Update:
I found the solution here https://forum.godotengine.org/114912/ive-been-trying-the-following-for-very-long-time-with-success

amberlimshin | 2022-06-23 13:46