0 votes

load: Loaded resource as image file, this will not work on export: 'res://resources/Myfile.png'. Instead, import the image file as an Image resource and load it normally as a resource.
Could any body explain what does this mean?
It works on windows but not on ios or android, what is the solution ?
This is the code I'm using to load the image, It works

var avatar_file ="res://resources/Myfile.png"
var img = Image.new()
var imagetexture=ImageTexture.new()
$AvatarSP.texture = imagetexture
in Engine by (108 points)

1 Answer

+1 vote
Best answer

You need to create the Image from the Texture, not the other way around.

var img_texture_path := "res://resources/Myfile.png"
var img_texture: StreamTexture = load(img_texture_path)
$AvatarSP.texture = img_texture

# You don't need to create an Image unless you need to edit the pixels or something
var img: Image = img_texture.get_data() # You can delete this line

I don't know the technical reason for this, but see the related issue:

by (226 points)
selected by

Thank you so much !!!

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.