- Home /
Embedding PNGs in an app to create a Texture2D on runtime in iOS
Hi,
I work on an app for kids that will require lots (500+) of high res (512x512 and above) sprites. The images are mostly lineart or clipart kind of images and they compress great to PNG (<25kb each in most cases) . All works like charm on Android but the iOS binary is a giant one. This is the result of my PNGs being converted. None of the compressed formats works for me.
What I look for is an option to create a Texture2D on the fly - I will only need to create a couple of them each time so the performance impact should be neglible.
Any ideas how to proceed?
Thanks in advance.
Answer by pl_ayground · Oct 05, 2016 at 09:26 PM
I think I have solved this with https://docs.unity3d.com/ScriptReference/Texture2D.LoadImage.html
Here is a short summary
Save your PNGs as *.bytes (in Resources folder)
Use TextAsset bytes Resources.Load("filename_without_bytes_extension) as TextAsset
Create a dummy texture (e.g. Texture2d(1,1))
Call this texture LoadImage method
Your answer
![](https://koobas.hobune.stream/wayback/20220612094052im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Using Texture2D.GetNativeTextureID() 0 Answers
My App Size is Too Large on iOS Because of Textures 0 Answers
How do I prevent Texture2D.EncodeToPNG from creating artifacts on iOS? 1 Answer
Bug - Texture "corrupted" after sending on server with MultipartformDataSection, only on iOS 1 Answer
Unity IOS: Texture format? 1 Answer