- Home /
Taking Screenshot and Reading Immediately Issue
Hi guys -
I have a program that is taking a screenshot with Application.CaptureScreenshot and then trying to read the .png file produced to edit it and save it into something else. After I use CaptureScreenshot, I have a piece of code that looks like this:
FileInfo fl = new FileInfo(filePath);
if (fl.Exists || File.Exists(filePath))
{
fileData = File.ReadAllBytes(filePath);
tex = new Texture2D(2, 2);
tex.LoadImage(fileData);
}
else
{
print("Can't Load!");
}
The "if" check fails 99% of the time in builds but never fails in the editor. I am 100% sure that the file exists that is stored in the variable "filePath." I've tried calling this code after a period of time, after I destroy the scene and reload it, and even after closing the game and restarting several times. I've tried editing the file path to include a reference starting at "C:/" and by looking for the file based on where the executable is. I've tried having the file path simply be the file name.
I think this has to do with my program not having permission to read the file because it's remaining locked after I capture the screenshot. Does anyone have an idea what might be going on and how I might fix it?
Your answer
Follow this Question
Related Questions
CaptureScreenshot writing to Phone, but persistentdatapath linking to the external card. 0 Answers
Capture Screenshots in a Row 0 Answers
iPhone System.IO.File.Exists() not working 1 Answer
[SOLVED] Bad PKCS7 While encrypting a file 1 Answer
Is accessing user documents folder possible on Unity3D? 0 Answers