||Topic was automatically imported from the old Question2Answer platform.
I’ve a canvas on which i draw a lot of stuff through draw* functions.
This canvas can be very big so it won’t fit viewport. The question is, is there a way to draw/save entire canvas to image or i have to do it other way?
I care about the final image quality.
Thanks for attention.
I think the way to go about this is using the
custom_viewport property of
I got saving of the image working with this giant label that is bigger than the main
For this node setup, the node Content is a
PanelContainer and therefore the size of the everything being draw on this
CanvasLayer. It doesn’t need to be a
PanelContainer just something that contains everything being drawn.
CanvasLayer has a script attached to it with the following code:
func _ready() -> void:
var viewport := Viewport.new()
viewport.disable_3d = true
viewport.size = $Content.rect_size
viewport.render_target_update_mode = Viewport.UPDATE_ONCE
custom_viewport = viewport
$"../TextureRect".texture = viewport.get_texture()
Viewport can be manually updated again (therefore updating the image) with the following line code:
custom_viewport.render_target_update_mode = Viewport.UPDATE_ONCE
If you just want to save the texture and then free everything you can call
.duplicate() on the texture (this must be done after at least one frame is drawn or else it’ll be fully black) and then
.queue_free() on the
Viewport and your
Hope this helps
Ah, big thanks
I’ve already done this with viewport but more bruteforce way, hope your code 'll help do it better way
ulabael | 2023-01-27 21:33