我在unity项目中使用了这个方法,将相机视口保存到文件系统中:
Application.Capturescreenshot(fileName)
这是很好的工作,但我希望它保存在一个特定的路径下。例如:Application.Capturescreenshot(c:/screenshots/filename);
我该如何管理它呢?太棒了!
发布于 2014-07-21 22:07:02
通过将绝对文件路径作为字符串传递,您可以很容易地使用它。在您的例子中,使用下面的语句应该可以很好地工作:
Application.CaptureScreenshot("C:/screenshots/filename");
请注意,它会给你一个错误,如果屏幕文件夹不存在。因此,如果您不确定这一点,您可以相应地修改代码:
// 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);
最后,如果你想使用相对路径而不是绝对路径,Unity提供了dataPath和persistentDataPath变量来访问项目的数据文件夹路径。因此,如果您想将屏幕截图存储在data文件夹中,可以相应地更改上面的folderPath:
string folderPath = Application.dataPath + "/screenshots/";
发布于 2018-01-24 21:45:13
var nameScreenshot = "Screenshot_" + DateTime.Now.ToString("dd-mm-yyyy-hh-mm-ss") + ".png";
ScreenCapture.CaptureScreenshot(nameScreenshot);
试试这个!
https://stackoverflow.com/questions/24851069
复制相似问题