orthehelper
orthehelper

Reputation: 4079

Application.Capturescreenshot(fileName) save to specific path

i am using in my unity project this method that saves the camera viewport to the file system:

Application.Capturescreenshot(fileName) 

it is work great but i want it to be saved under a specific path. for example : Application.Capturescreenshot(c:/screenshots/filename); how can i managed this? thnaks!

Upvotes: 0

Views: 11621

Answers (2)

Ismael Ash
Ismael Ash

Reputation: 11

        var nameScreenshot = "Screenshot_" + DateTime.Now.ToString("dd-mm-yyyy-hh-mm-ss") + ".png";
        ScreenCapture.CaptureScreenshot(nameScreenshot);

Try this !

Upvotes: 1

anokta
anokta

Reputation: 486

You could use the absolute file path easily by passing it as a string. In your case, using this statement should work just fine:

Application.CaptureScreenshot("C:/screenshots/filename");

Note that it will give you an error if screeshots folder does not exist. Hence, if you are uncertain of that, you could modify the code accordingly:

// File path
string folderPath = "C:/screenshots/";
string fileName = "filename";

// Create the folder beforehand if not exists
if(!System.IO.Directory.Exists(folderPath))
    System.IO.Directory.CreateDirectory(folderPath);

// Capture and store the screenshot
Application.CaptureScreenshot(folderPath + fileName);

Lastly, if you want to use a relative path instead of an absolute one, Unity provides dataPath and persistentDataPath variables to access the data folder path of the project. So, if you want to store the screenshots inside the data folder, you could change the folderPath above accordingly:

string folderPath = Application.dataPath + "/screenshots/"; 

Upvotes: 3

Related Questions