I am working on a project which downloads png files from a web server and loads them into a Texture2D for use.
The following code highlights a very severe problem with the Teture2D LoadImage method. Namely, it takes 250ms to load a 500x500 pixel texture.
DateTime nowTime = DateTime.Now;
string completedPath = "A local path"
byte [] textureData = File.ReadAllBytes(completedPath);
Debug.Log ("Loading bytes " + (DateTime.Now - nowTime).TotalMilliseconds + "ms");
nowTime = DateTime.Now;
Texture2D tex = new Texture2D(0,0);
tex.LoadImage(textureData);
Debug.Log ("Loading texture " + (DateTime.Now - nowTime).TotalMilliseconds + "ms");
The output from this code is as follows (When run on an iPhone 4):
Loading bytes 10.187ms
Loading texture 235.297ms
Is there a faster way to load a png from disk? This seems like a ridiculous amount of time to take to load a simple image.
If possible I would like to avoid the use of Asset Bundles.
As a comparison. Loading the same texture on the same device (iPhone 4) using pure objective C takes 10 ms.
float timeNow = CACurrentMediaTime();
UIImage *image = [UIImage imageNamed:@"brand1365761681365.png"];
NSLog(@"Time taken on ios %f ms", (CACurrentMediaTime() - timeNow)*1000.f);
Time taken on ios 10.370380ms
Loading the texture using the WWW class takes even longer, around 1000ms.