- Home /
Loading 8192x8192 textures at runtime on android
I'm using 8192x8192 truecolor textures in my android project and they work fine when used normally, but now I'm trying to switch to load them at runtime from the streaming assets folder using WWW.LoadImageIntoTexture. (note: I'm doing this because when they are not in the streamingAssets folder the bundle is very large; each 20mb image becomes 256mb).
This works fine when the build platform is standalone but when I switch it to android and run it in the editor I just get a blue texture rather than my image (similar result when running on a device except it's black).
A simplified project with just a 20 line script and an image (20mb) is here: https://drive.google.com/file/d/0ByNPa9Pa1jJ8YVZ1TDdISzFpb3c/view?usp=sharing
Full Script:
public class OptimizationTests : MonoBehaviour {
WWW localFile;
void Start()
{
string path = "file://" + Application.dataPath + "/StreamingAssets" + "/8kimage.jpg";
StartCoroutine("LoadTexture", path);
}
public IEnumerator LoadTexture(string absoluteImagePath)
{
Texture2D texture = new Texture2D(4, 4, TextureFormat.RGBAFloat, false);
localFile = new WWW(absoluteImagePath);
yield return localFile;
localFile.LoadImageIntoTexture(texture);
GetComponent<Renderer>().material.mainTexture = texture;
}
}
You need to use logcat to find out what's going on on the device but if you're planning to release this I'd recommend you reconsider your texture size - I own 4 Android test devices and I think only one of them will handle textures that large.
Thanks for the reply. It's not a device issue because it happens in the editor as well, but I have also looked at the logcat output and there is no additional info. 8k textures work on all devices I am supporting (it's a very limited subset).
Have you actually checked SystemInfo.maxTextureSize? Also note that most android devices don't have that much memory. Regardless of the supported texture size you may just run out of memory. $$anonymous$$y Nexus7 (first gen) only supports 2048 texture size.
I'm running into exactly the same problem in 2018, did you ever figure this out?
Not sure if my problem was actually exactly the same, but I fixed it by instancing the material I was using.
$$anonymous$$y texture was nowhere near 8k though.
[1]: /storage/temp/123691-gpu-instancing.png
I agree with @tanoshimi there should be no reason you need a texture that big for android. im not sure if this helps but this has allways been the the way ive done it and it always worked for me:
using System.IO;
byte[] by = File.ReadAllBytes("filepath here");
Texture2D paper = new Texture2D(2,2);
paper.LoadImage(by);
Your answer
Follow this Question
Related Questions
dynamic images for textures ar runtime 2 Answers
Changing terrain texture at runtime 1 Answer
Problem with texture swapping at runtime (Android only) 0 Answers
Passing texture to android plugin 0 Answers
Save a Texture2D for android 1 Answer