- Home /
Loading Images using WWW into a different texture format
Hi,
We are trying to load images from an external resource. In order to do this, we used WWW class and then create a new Texture2D image. We're using the sample script from this source: http://docs.unity3d.com/Documentation/ScriptReference/WWW.LoadImageIntoTexture.html
renderer.material.mainTexture = new Texture2D(1024, 1024, TextureFormat.PVRTC_RGBA4, false);
while(true) {
// Start a download of the given URL
var www = new WWW(url);
// wait until the download is done
yield www;
// assign the downloaded image to the main texture of the object
www.LoadImageIntoTexture(renderer.material.mainTexture);
}
For some reason, the loaded image is taking up too much memory and it looks like it's loading an RGBA32 format instead of the PVRTC_RGBA4 format.
Our target platform is iOS and we're assuming that the texture format is supported.
Our Unity version is 3.5.0.f5
Thanks
Answer by Paulius-Liekis · Aug 01, 2012 at 01:54 PM
You're loading png or jpg, so they are not compressed with PVRTC, so you get texture in RGBA32. Unity can create PVRTC textures only on Editor, because that's where compression code lives. It can not compresses textures in runtime.
Anyway, I think you're problem is that you have infinite loop. At least I don't see any break statement.
oh, okay. So there is no runtime conversion (workaround) to pvrtc? Anyway, The code provided is just a sample code the main problem was that I was using too much memory since Unity loads PNGS into RGBA32 format. thanks!
Answer by codehead · Oct 21, 2012 at 10:20 PM
You can download a pre-compressed texture from the server and upload it to the device texture memory. I'm doing it on Android and posted the code to another question :)
http://answers.unity3d.com/questions/184840/download-and-use-pvrtc-texture-ios.html