Loading textures from disk Problem

Godot Version

4.4.1

Question

my problem is loading Image, by path from computer to godot. im making a "launcher" for myself and in order to study, but for unknown cause its not loading, screens below
EDIT: there is a mistake in screen, “nazwa” at start is name of a folder, correctly explained in comments in “RediSciezka()”

Please make sure to post code as formatted text instead of as an image:
```gd
# code
```
Will look like this:

# code

The first warning (“The function “create_from_image()” is a static function but it was called from an instance […]”) means that you should use ImageTexture.create_from_image(...) instead of tex.create_from_image(...).
So the function should look like this:

var img = Image.new()
var err = img.load(sciezunecka)
var tex
if err == OK:
	tex = ImageTexture.create_from_image(img)
else:
	print("I'm not typing this out")

The errors are there because the file you’re loading (IkonaGry.png) appears to be corrupt.
Is it a non-PNG file that was just renamed to have the “.png” extension? If so, use an online converter to convert the original file to a PNG; just renaming the file doesn’t work.
Otherwise, I suggest opening the file in a program like Paint to see if it’s valid.

THAT WORKS!!
thank you very much, but its weird that my version didint work, ImageTexture was assigned to tex,
in my eyes it looks like:

tex.create_from_image(img) <-> ImageTexture.create_from_image(img)

but if it works, i wont ask. btw your print message is hillarious xd
and from now i will post code as you said, pardon!

Well, there’s a difference between ImageTexture and ImageTexture.new(). You assigned ImageTexture.new() to the variable tex, which means that it has a value of the type ImageTexture. Just ImageTexture alone isn’t a value (so you can’t assign it to a variable) but a class or type.
Static functions, like ImageTexture.create_from_image(), are supposed to be called on the type, which is why tex.create_from_image(img) caused a warning.
Non-static functions, like Image.load(), need to be called on the value, so Image.load(sciezunecka) would cause an error while img.load(sciezunecka) works.
In the documentation, you can see if a function is static by looking at the tags to the right of its name:
Static:
image
Not static:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.