Unity3D: Image is not saving in HDD
Application.CaptureScreenshot() has atleast 2 subtle use issues that come to mind:
On iOS it won't accept a path, it will only write to the Documents folder. So your "SavedScreen.png" is going to be in:
Application.persistentDataPath + "/screenshot.png";
It is asynchronous, so the file will take a few frames (if not a second) to write to the file system. And it doesn't tell you when it is finished.
I prefer the full control of ReadPixels, but if you want to use CaptureScreenshot, you should wait atleast 2 seconds before you access the file:
void CaptureScreenshot()
{
StartCoroutine(CaptureScreenshotCo());
}
IEnumerator CaptureScreenshotCo()
{
string file = "screenshot.png";
string path = string.Format("{0}/{1}", Application.persistentDataPath, file);
// capture screenshot async
Application.CaptureScreenshot(file);
// wait for file to be saved
yield return new WaitForSeconds(2f);
// now do something with file...
}
Related videos on Youtube
Sharath Kumar
Updated on November 27, 2022Comments
-
Sharath Kumar about 1 month
I am working on an mobile app using camera. My issue is the image snapped is not saving in the app root folder. Here is the snippet of code am using to capture the screen.
Application.CaptureScreenshot("SavedScreen.png");
But this doesn't saving anything in the internal storage.Can any one help me out. Cheers.
-
Chris McFarland about 8 yearsPossible duplicate of stackoverflow.com/questions/11725548/…
-
Sharath Kumar about 8 yearsI have tried all that. But my snap is not saving. Do should I grant any permissions for that. @Chris
-
peterept about 8 yearsWhich platform are you on?
-