Unity内一般有三种截屏的方法:
- Application.CaptureScreenshot
- Texture2D.ReadPixels
- RenderTextures
图片保存地址一般设为: Application.persistentDataPath + “/screen1.png”
参考persistentDataPath的文档说明:The value is a directory path where data expected to be kept between runs can be stored. When publishing on iOS and Android, persistentDataPath will point to a public directory on the device.
下面我们来看具体的实现:
Application.CaptureScreenshot
文档上已将此方法标记为 Obsolete 。
https://docs.unity3d.com/ScriptReference/Application.CaptureScreenshot.html
优点:简单,可以快速地截取某一帧的画面、全屏截图
缺点:
1. 不能针对摄像机截图
2. 定制大小截图不方便
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour {
void OnMouseDown() {
Application.CaptureScreenshot(Application.persistentDataPath + "/CaptureScreenshot.png");
}
}