How can I get an image from local storage and use it as a texture at runtime?

Hi,

I would like to get a .png.jpg image stored in local storage on my PC or Android and furthermore use it as a texture in the game.

So far I have been able to change the texture at runtime and get the path to the image from local storage.

But I’m not sure how to convert the local storage path to Texture2d.
I did some research and couldn’t find anything.

I know there is a function called DownloadImage that will allow me to turn an image from the web into texture2D.
I would like to do the same with images in local storage.

I would be glad to get some answers.
Thanks for reading to the end.

2 Likes

Hello @Russy_18, you should add this image file to your project. One way to do this is simply drag and drop the file into the Editor’s ContentBrowser inside the folder where you would like to save it. Unreal should then convert this file to a uasset where you will probably need to specify that it is a texture (I don’t remember if it detects it as a texture automatically or not).

Once the file is in the project’s content you can reference it and use it as you like inside your game.

Hope this helps, let me know if this solves your problem, good luck!

1 Like

Thank you kribbeck!
sorry I may have been a little short in my description.
I want to get images from local storage on my PC or Android “at runtime.”
The use case is that I want to texture the image from the game user’s own PC or device.

Hi @Russy_18!

If you are attempting to pull the desktop wallpaper for windows, check out this previous thread that had a very similar goal:

How can I change the computer desktop image using the unreal engine?

I hope the above solution works for you!

Thank you Quetzalcodename!
That approach may not solve my problem.

What I want to do is load the images stored in local storage into the game.

I am able to get the file path of the image.
I need to know how to load that image as a texture at runtime.

Hey @Russy_18,

What version of Unreal are you using? If you are using 4.27, there is now a plugin that does just what you are looking for:

If not, it looks like your best bet is to use the Image Wrapper Class using C++. Check out the following thread that looks to be more geared and has a solution to what you are looking for:

jpg to texture at runtime

I hope one of the above solutions works for you!

3 Likes

Thank you for your prompt reply.
I just tried the RuntimeImageLoader and it did display the local image easily and cleanly!

I knew I had to use C++ to solve this problem, and I wanted to do more research on C++.
The content of that thread was also very helpful!

Thank you so much!!:laughing:

1 Like

Here’s the solution to your problem!

Import an Image from Explorer in Runtime - Development / Programming & Scripting - Epic Developer Community Forums (unrealengine.com)