How to put image / screenshot into computer clipboard (Godot 4.2, Godot 4.x)
-
(This is a repost because I realized I put the original post in the wrong part of the forum.)
Just for funsies, here's the code I'm using to take a screenshot. You may use it if you like! I'd like to make it so that it also takes that image it just took (
image.save_png(screenshot_path)
) and puts it into the computer's clipboard. That way I can just press Ctrl+V and it'll paste that screenshotextends Node2D @export_category("Screenshot Settings") ## If true, the screenshot will be upscaled. ## If false, the screenshot will be at its native resolution. @export var upscale : bool = true ## Upscale by what factor? @export var scaleFactor : int = 5 @onready var resizedWidth : int = get_viewport_rect().size.x * scaleFactor @onready var resizedHeight : int = get_viewport_rect().size.y * scaleFactor func _process(_delta): TAKE_SCREENSHOT() func TAKE_SCREENSHOT(): if Input.is_action_just_pressed("SCREENSHOT"): var date = Time.get_datetime_string_from_system().replace(".","_").replace(":","_") var screenshot_path = "user://"+ "screenshot_" + date + ".png" var image = get_viewport().get_texture().get_image() if upscale: var resizedImage = Image.new() resizedImage.create(resizedWidth,resizedHeight,false,Image.FORMAT_BPTC_RGBA) image.resize(resizedWidth,resizedHeight,Image.INTERPOLATE_NEAREST) resizedImage.blit_rect(image,Rect2(Vector2.ZERO,image.get_size()),Vector2.ZERO) image.save_png(screenshot_path)
I've tried putting
DisplayServer.clipboard_set(image)
orDisplayServer.clipboard_get_image()
afterimage.save_png(screenshot_path)
, and looking the solution up online and I'm all out of ideas lolAlso, I'm trying to figure out what the default
screenshot_path
should be. I'd like to put screenshots in the user's Pictures folder or maybe the folder the game's EXE is in, but I don't really know how to do that either. As far as I can tell,user://
doesn't seem to lead anywhere.