How to save sprite node into image file

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

Hello, I want to save the sprite node to an image file and i’ve tried this code: $Sprite.get_texture().get_data().save_png()
but it only save the texture not sprite completely like modulate, scale, rotation etc.

so, how to save sprite node into image files? or, how to convert sprite node to texture and save the texture into image?

*i don’t want a screenshoot

:bust_in_silhouette: Reply From: alexp

Try putting the Sprite in a Viewport, which keeps what it renders as a dynamic texture. Then you can callviewport.get_texture().get_data().save_png()

:bust_in_silhouette: Reply From: love_this_name

I’m not super sure if this would work, but try this:

  1. Copy sprite node and instance it as a child of a viewport.

  2. Get viewport texture (make sure viewport background is set to transparent)

If it works, this would be like taking a screenshot but ignoring every other node.

love_this_name | 2022-10-16 11:12

Thank you, the problem when i use screenshoot is the backround and now the backround is transparent

user1845 | 2022-10-17 03:41