Loading image from file at run time?

How do I load an image from file path at runtime?

I’m building a game where I want the user to configure a map before starting. Part of the configuration is allowing them to upload an image that I then display on their screen when they start the level.

I have searched the forum and I can’t find anyone that has done this and provided a good explanation on how they did it.

This game is for desktop only so I can use the local file system to its full extent.

How do you want to do the “upload”? My suggestion is take a Panel Sprite object and apply the following

Is the “Set Image” method still a thing on the Panel Sprite? I can’t seem to find it

Sorry found it. For anyone else it’s reference is this:

Ok I’m struggling to get this working. Does this already need to be in your resources for it to work? I’m using a Windows machine so also dubious about the absolute pathing.

I just get this error message in the console:

Unable to find texture for resource "C:\Users\Username\Pictures\Map Frame Demo.png".

The file exists and pasting this path in my explorer load the file.

Sorry, my mistake. I had this already in my resources and the name was the same. I guess this option only allows to change the image from the resources.

There are maybe workarounds for this. I will check later on. Maybe our last chance is to use a JS block to do this. Would like to hear some more from the GD experts here on this topic.

Ok I made some progress on this. I can load an image from the local drive by following this example:

You use the file:/// instead of a URL. For example I used file://C:/Users/Username/Pictures/Map Frame Demo.png for the url scene variable value of the example.

1 Like