- Home /
Is it possible to turn JPEG images into textures at runtime in Unity on iOS devices?
Note: High level answers of the type "Read the documentation on the XXX function" appreciated here. I'm not sure where to begin researching a solution for this because everything I've done before has used PNGs built into the project.
Question: I've got an app I want to build in Unity. The app takes information from an RSS feed provided by a third party (under license, I'm not stealing, but they control the format of the data, not me.) I need to take that data an parse it and pull out text and images. I want to put the images into textures on objects in Unity.
I can use an RSS parser in objective-C. I have unity Pro, so I can use the "native code" functionality here. But I am curious how I take the JPGs (whose URLS are in the RSS feed) and convert them into textures I can apply to objects within the Unity Scene.
The JPEGS are of a uniform size. The meshes they will be applied to are all instantiated from the same prefab and are identical, except for the texture.
I can likely convert them to PNGs on the Objective-C side. So, maybe my question is: How do I create a couple hundred instances of a prefab, all of which have the same material, but each of which has a different texture?
Or can I programmatically create materials from JPEGs?
Maybe the process is, turn them into PNGs, move them from the Objective-C side and then create materials on the fly?
Appreciate any pointers if there is an easier way to do it, or if there's any gotchas I need to watch out for.
For instance, I understand that the Unity development environment does some processing to optimize textures during build, and I'll need to somehow make my images be in the right format for feeding to the game engine, at runtime.
Thanks.
Found Texture2D.loadImage which takes a TextAsset and apparently works with JPEGs, which solves part of the path. If the format is DXT1 then the resulting image will be compressed. Is this compatible with iOS? (EG: create a Texture2D with DXT1 format, then use loadImage and feed it an array of jpeg bytes?)
This seems like a solution, the only method that I could find for loading an image into a texture at runtime, but TextAsset seems to be designed to work with txt files in your project. I can't create one by loading an image from a URL.
Your answer
![](https://koobas.hobune.stream/wayback/20220613094701im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Some textures don't load on iOS 0 Answers
A node in a childnode? 1 Answer
Why a 109kb .png file teakes 8mb in unity? 1 Answer
u3dxt causing failed validation 2 Answers