Hello,
I am developing a project, where I need to first save a screenshot to a file and then read from that file to get a texture. I got everything working correctly on my PC and now I am trying to make a build for Android but I cannot find a way to make it happen.
Right now, my code looks as follows:
Saving the screenshot to a file:
path = "jar:file://" + Application.dataPath + "!/assets/";
ScreenCapture.CaptureScreenshot(path + _name);
Loading textures from the files (libraryLength is a number of the files, photos is an array of textures, while photoNames is an array with names of the files)
path = "jar:file://" + Application.dataPath + "!/assets/";
for(int i = 0; i < libraryLength; i++)
{
photos _= LoadPNG(path + photoNames*);*_
}
LoadPNG method:
public static Texture2D LoadPNG(string filePath)
{
Texture2D tex = null;
byte[] fileData;
if (File.Exists(filePath))
{
fileData = File.ReadAllBytes(filePath);
tex = new Texture2D(2, 2);
tex.LoadImage(fileData);
}
return tex;
}
I’ve tried using many different combinations of paths, both for StreamingAssets and Resources folders but all of them ended up not working on my mobile. The Write Permission is set to External ( SD Card) in the Player Settings.