How can I get image data from a script?

DschoonmakerDschoonmaker Posts: 260Member
in 3D

I have an ImageTexture variable, and am trying to get the color from it at a certain position. I found I can get the Image with:

heightmap.get_data()

and there's a function to get a pixel:

heightmap.get_data().get_pixel(64,64)

but if I try it, I get this error:

Image must be locked with 'lock()' before using get_pixel().

so I tried putting this line before get_pixel():

heightmap.get_data().lock()

but nothing changed. Do you have any idea why?

Best Answer

  • SIsilicon28SIsilicon28 Posts: 749
    edited July 7 Accepted Answer

    Try this.

    var image := heightmap.get_data()
    image.lock()
    image.get_pixel(some, numbers)
    

Answers

  • SIsilicon28SIsilicon28 Posts: 749Moderator
    edited July 7 Accepted Answer

    Try this.

    var image := heightmap.get_data()
    image.lock()
    image.get_pixel(some, numbers)
    
  • DschoonmakerDschoonmaker Posts: 260Member

    It worked, thank you!

  • CalinouCalinou Posts: 452Admin Godot Developer

    Note that Godot 4.0 won't require locking/unlocking images anymore.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file