How to get a pixel color monitor?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Tort
:warning: Old Version Published before Godot 3 was released.

How to get a pixel color monitor?
For example the color of the pixel under the cursor.

:bust_in_silhouette: Reply From: Matt_UV

In an older project, I used that line

color = get_node("Sprite").get_texture().get_data().get_pixel(cursor_pos.x,cursor_pos.y)

It may not be the way to do it, but it works.
Here, cursor_pos is the position of a Position2D that I had created, but you can adapt your code as you need :wink:

get_node("Sprite")

That’s not what I’m looking for. With sprites, I already understood.
Interested in receiving pixel color monitor that is under the cursor may be any object, including a 3D object.

Tort | 2016-05-11 23:00

Have you tried with a screen capture ?

var image = get_viewport().get_screen_capture()
var color = image.get_pixel(cursor_pos.x,cursor_pos.y)

Although it might be quite ressource consuming if you do that at every frame…

PS : if get_screen_capture() doesn’t work, check that:
http://op.godotengine.org/topics/8759?r=14346

Matt_UV | 2016-05-11 23:15

Thanks.
Solved

get_viewport().queue_screen_capture()
var image = get_viewport().get_screen_capture()
print(image.get_pixel(get_global_mouse_pos()[0], get_global_mouse_pos()[1]))

Tort | 2016-05-12 09:44