WWW.LoadImageIntoTexture works on Android but fails on UWP with Log: "Cannot load image"
Hi,
I load a Image from a URL. It works good on Android but on UWP it cant download the Image with following Log: "Cannot load Image". Tested it on PC, Emulator and Mobile Phone.
IEnumerator Start()
{
Texture2D tex;
tex = new Texture2D(4, 4, TextureFormat.DXT1, false);
using (WWW www = new WWW(url))
{
yield return www;
www.LoadImageIntoTexture(tex); ---> here log calls!
GetComponent<Renderer>().material.mainTexture = tex;
}
}
Do I have to set Special permissions in UWP or why doesn't it work?
I hope you can help me.
Answer by mjace · Jan 15, 2019 at 06:39 PM
Two possibilities come to mind from recent experience:
I'd check the bit depth of the image you are trying to load. I noticed that the encoding of images done from UWP API sometimes sets a 32 bit depth by default. It appears that some of Unity's methods, such as Texture2D.LoadImage(), only support loading 24 bit depth images for jpeg, for example. It may be that the WWW.LoadImageIntoTexture() has a similar limitation - only expecting/loading a particular bit depth for a particular format of image file. If this applies to your situation, you may be interested in this code snippet (which helped me get on the right track): https://gist.github.com/alexsorokoletov/71431e403c0fa55f1b4c942845a3c850
UWP does also require adding files to a future access list before reading in most locations on the file system. In general, you have to add most things to the file access list outside of the UWP appx installation path. See https://docs.microsoft.com/en-us/uwp/api/windows.storage.accesscache.storageitemaccesslist for more details.