之前项目中需要用到截图功能,经过查找找到3种方式,这里做一个记录。
Application.CaptureScreenshot
Application
类下的
CaptureScreenshot
方法,截取的是某一帧时整个游戏的画面,或者说是全屏截图吧。
以下是两个重载的函数。其中
filename
参数为截图后保存下来的文件名;
superSize
参数为增加分辨率的因数:
//// 摘要:// Captures a screenshot at path filename as a PNG file.//// 参数:// filename:// Pathname to save the screenshot file to.//// superSize:// Factor by which to increase resolution.[Obsolete("Application.CaptureScreenshot is obsolete. Use ScreenCapture.CaptureScreenshot instead (UnityUpgradable) -> [UnityEngine] UnityEngine.ScreenCapture.CaptureScreenshot(*)",true)]publicstaticvoidCaptureScreenshot(string filename);//// 摘要:// Captures a screenshot at path filename as a PNG file.//// 参数:// filename:// Pathname to save the screenshot file to.//// superSize:// Factor by which to increase resolution.[Obsolete("Application.CaptureScreenshot is obsolete. Use ScreenCapture.CaptureScreenshot instead (UnityUpgradable) -> [UnityEngine] UnityEngine.ScreenCapture.CaptureScreenshot(*)",true)]publicstaticvoidCaptureScreenshot(string filename,int superSize);
通过上面的代码也可以看出,在新版的Unity中该函数被废弃了。新的系统函数类是
ScreenCapture
。
ScreenCapture
以下为系统类
ScreenCapture
:
//// 摘要:// Functionality to take Screenshots.[NativeHeader("Modules/ScreenCapture/Public/CaptureScreenshot.h")]publicstaticclassScreenCapture{
publicstaticvoidCaptureScreenshot(string filename);//// 摘要:// Captures a screenshot at path filename as a PNG file.//// 参数:// filename:// Pathname to save the screenshot file to.//// superSize:// Factor by which to increase resolution.//// stereoCaptureMode:// Specifies the eye texture to capture when stereo rendering is enabled.publicstaticvoidCaptureScreenshot(string filename,int superSize);publicstaticvoidCaptureScreenshot(string filename,StereoScreenCaptureMode stereoCaptureMode);publicstaticTexture2DCaptureScreenshotAsTexture

发布评论