- Home /
iOS Find ScreenShot
Hello,
I know there are questions relating to this, but i am having problems that don't seem to be covered. Basically i'm using Application.CaptureScreenshot(), trying to yield until the file has been created, then apply this file to a texture. Works perfectly in editor, not on iOS though. I was having trouble with the yield, so i did a test with WaitForSeconds, and it just can't find the file. I've looked on the device though, and they are there, in the documents folder, as i'd expect from from what i've read about CaptureScreenshot.
I need to actually save the file as i want to post it to FB once i sort this out.
Any help would be GREATLY appreciated. Thanks.
IEnumerator TakeScreenshotAndLoadItIntoTexture(string filename) {
Application.CaptureScreenshot(filename);
/*while(!File.Exists(filename)){
debugString = "Saving";
yield return null;
}
*/
FileInfo info = new FileInfo(filename);
while(info == null || info.Exists == false){
debugString = "Saving";
info = new FileInfo(filename);
yield return null;
}
debugString = "Saved";
WWW screenShot = new WWW("file://" + filename);
yield return screenShot;
print ("Loading");
debugString = "Loading";
print("Done " + Time.time);
previewTexture = screenShot.texture;
}
btw, i call it with:
StartCoroutine(TakeScreenshotAndLoadItIntoTexture(Application.persistentDataPath +"screenshot" + "_" + System.DateTime.Now.ToString("yyyy_MM_dd_hh_mm_ss") + ".png"));
Answer by udaanparvaz · Sep 25, 2012 at 01:55 PM
The Application.captureScreenshot("anyname.png"); save the png to documents folder itself, you don't need to give it a path. What you are doing here is saving a screenshot of name (Application.persistentDataPath +"screenshot" + "_" + System.DateTime.Now.ToString("yyyy_MM_dd_hh_mm_ss") + ".png") you should only pass the name...not the path to documents directory.
Please see into it.
Hey,
Thanks for the reply. Originally i was passing only the name as you suggested, i added the Application.persitentDataPath in a effort to eli$$anonymous$$ate any possible path issues. What i'm saying is the result is the same regardless. Neither of the while statements ter$$anonymous$$ate even though the file is created.
Have you tried passing the path manually ins$$anonymous$$d of giving the filename parameter to it?? Because I successfully tested this if(File.exists(Application.persistentDataPath+"/screenshot.png")) { //where my Application.captureScreenshot("/screenshot.png"); }
This method checked successfully the existence of my screenshot...This was tested on IOs just yesterday....I had to take the screenshot to gallery so i was checking the file existence before giving it to my native code....Please do keep in $$anonymous$$d that Unity takes some time to write the screenshot at the documents path...