Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading resources from user:// #18367

Closed
blaze-the-star opened this issue Apr 22, 2018 · 4 comments
Closed

Loading resources from user:// #18367

blaze-the-star opened this issue Apr 22, 2018 · 4 comments
Labels

Comments

@blaze-the-star
Copy link

blaze-the-star commented Apr 22, 2018

An error from #2319 is occurring in Godot 3.0.2. This error does not occur when loading a tscn file.

ERROR: _load: No loader found for resource: user://icon.png
At: core/io/resource_loader.cpp:186.

@PJB3005
Copy link
Contributor

PJB3005 commented Apr 23, 2018

I may be wrong here but isn't the problem here that loading an image like that when it's not imported by the editor doesn't work? The resource loader tries to load SteamTextures which don't exist for user://. You could try using ImageTexture I believe.

@LinuxUserGD
Copy link
Contributor

LinuxUserGD commented Apr 23, 2018

func load_jpg(file):

	var jpg_file = File.new()

	jpg_file.open(file, File.READ)

	var bytes = jpg_file.get_buffer(jpg_file.get_len())

	var img = Image.new()

	var data = img.load_jpg_from_buffer(bytes)

	var imgtex = ImageTexture.new()

	imgtex.create_from_image(img)

	jpg_file.close()

	return imgtex

func load_png(file):

	var png_file = File.new()

	png_file.open(file, File.READ)

	var bytes = png_file.get_buffer(png_file.get_len())

	var img = Image.new()

	var data = img.load_png_from_buffer(bytes)

	var imgtex = ImageTexture.new()

	imgtex.create_from_image(img)

	png_file.close()

	return imgtex

File is the path in this case, like

var img = "user://image.jpg"
texturebutton.normal = load_jpg(img)

@LinuxUserGD
Copy link
Contributor

LinuxUserGD commented Apr 23, 2018

duplicate: #17748 (#17848 is the new issue)

@bojidar-bg
Copy link
Contributor

Yes, looks like a duplicate of #17848 indeed. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants