- Home /
Black texture shows using WWW on Android phone
So I'm trying to load in a texture, stored on the phone's internal storage. I get the path of the file as follows:
string[] filePaths = Directory.GetFiles(m_FileDir);
if ( filePaths[0] != null )
{
StartCoroutine( ImportFile( filePaths[0] ) );
}
I'm pretty sure that bit works as within the co-routine I added an output for the width and height of the loaded texture, which is correct.
The code inside the co-routine is:
WWW www = new WWW( "file:///" + _dir );
yield return www;
m_Text.text = _dir + " \n " + www.texture.width + " \n " + www.texture.height;
Texture2D tex = new Texture2D( 4096, 1271, TextureFormat.ETC2_RGB, true );
www.LoadImageIntoTexture(tex);
m_Mesh.renderer.material.mainTexture = tex;
I looks like it should be correct, but it only produces a black texture.
Any help would be greatly appreciated.
EDIT:
The other textures in the scene are 4096:xxxx and setting the aspect ratio of the texture2D to 2048:635 also produces a black texture. Testing on a Samsung Galaxy S5
Answer by sh3rifme · Apr 30, 2015 at 06:55 PM
Well, after some tinkering, i got it working.
Now i'm using:
Texture2D texture = www.texture;
I'm not 100% sure why it was not working, but i believe it had something to do with trying to load the image into a texture that was of the incorrect format/size, as once i stopped trying to constrain the texture, it began to work.
Currently using an android plugin to get the texture re-sizing working instead.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Access existing folders android 0 Answers
display www.texture from url causes crash in some devices 0 Answers
How to download multiple images using WWW api and show in listview. 0 Answers