+2 votes

Want to achieve something like a photo album, showing pictures not in the assets folder, but elsewhere on the HD of a user. Loading a texture directly with:

get_node("../TextureRect").texture = load(imgFile)

gives an Error like "No loader found" if say a ".png" file is outside the asset folder. I can load this "external" file into an Image object without error, but I found no way to convert this Image to a texture and assign that texture, like so:

func _on_Button_pressed():
    var imgFile = "F:/pictures/" + fileList[imgNumber]
    imgNumber += 1
    var img = Image.new()
    img.load(imgFile)
    get_node("../TextureRect").texture.set_data(img)

Before I set the texture of the "TextureRect" to an "ImageTexture" with size 640 x 360. With this there always is an error like:

"Condition '!texture->active' = true"

Cannot figure out what I am doing wrong.

in Engine by (62 points)

1 Answer

+5 votes
Best answer

Try to create a texture from that image and set it instead (don't use set_data).

by (262 points)
selected by

Thank you so much. This one works:

func _on_Button_pressed():
    var imgFile = "F:/pictures/" + fileList[imgNumber]
    imgNumber += 1

    var img = Image.new()
    var itex = ImageTexture.new()
    img.load(imgFile)
    itex.create_from_image(img)
    get_node("../TextureRect").texture = itex

This does not work in android. I am getting black screen.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.