- Home /
Load Image from local folder on Android not working
Hi, I have a canvas (myCanvas) component, and I try to set this file(DSC06754.JPG about 7 MB, 4912x2760), but it gives me a blue screen, and no errors. With other images it works, but this one that I shoot with my own camera don't want to show! What can be the problem? I discover that if I resize that to lower resolution than I can see the picture ok.
Here is my code that I use to load image to my canvas:
private IEnumerator LoadPicture(string file)
{
WWW www = new WWW("file://" + file);
yield return www;
www.LoadImageIntoTexture(_texture2D);
myCanvas.GetComponent<CanvasRenderer>().SetTexture(_texture2D);
}
This is how it looks:
And if I copy from my computer to Android a picture (Penguins.jpg) and load, it looks ok.
did you find an answear by two years after? I have the same issue
The image is most likely simply too large An image of the size (4912x2760) would require about 40$$anonymous$$B of memory on the graphics card. Though if the hardware doesn't support that large images there's no way around that. To be able to load such a large image you would have to use a third-party image library that can load the image into memory and then downsample it so you can hand it over to Unity.
Answer by Suduckgames · May 23, 2017 at 07:24 AM
You are probably having problems with android memory, Android memory is very limited so instead of load the texture direcly you will need to resize the image, In case you still want the same size, you will need to make a image loader manager in order to specify the quality, dpi, and others options instead of direct load it into the canvas
Answer by Z-Farmer · Dec 04, 2017 at 02:18 AM
this is a unity bug, i will show u hot to pass this bug
byte[] bytes = www.GetBytes();//Config.ReadFileByte(path);
// tex2d = new Texture2D(1,1,TextureFormat.ARGB32,false);
// do not disable minmap! it importent
tex2d = new Texture2D(1,1,TextureFormat.ARGB32,true);
ImageConversion.LoadImage(tex2d, bytes, true);
sky.SetTexture("_Tex", tex2d);
when the picture size more than 4k and the minmap was disable it will back the blue picture.... i not sure what they happen but this is the reson...
so use my method can load success, but when
1.disable minmap
2.pciture size more than 4k
it still will get a blue pciture...
Your answer
Follow this Question
Related Questions
How to load image from android gallery 0 Answers
pick image from android gallery 3 Answers
Save and Load in the build 0 Answers
my textures aren't working (bmp files issue) 3 Answers
Android loading indicator missing after splash screen 1 Answer