access pixels of sprite2d

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

From a script, I’d like to get the color values at specific positions of a sprite. Is this possible somehow? In my case, the sprite is not drawn but only contains data for an algorithm. Is there another way to just load an image an get its color values?

:bust_in_silhouette: Reply From: Zylann

Yes, you don’t have to create a sprite for this.

# This gives you an ImageTexture
var image_texture_resource = preload("my_image.png")

# This gives you an Image
var image = image_texture_resource.get_data()

# This gives you a pixel (check the doc)
image.get_pixel(x, y)