Topic was automatically imported from the old Question2Answer platform.
Asked By
igbow
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()
img.load(avatar_file)
var imagetexture=ImageTexture.new()
imagetexture.create_from_image(img)
$AvatarSP.texture = imagetexture
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: