public static IEnumerator ScreenShot()
{
yield return new WaitForEndOfFrame();
int width = Screen.width;
int height = Screen.height;
Texture2D tex = new Texture2D(width, height, TextureFormat.RGB24, false);
tex.ReadPixels(new Rect(0, 0, width, height), 0, 0, true);
byte[] imagebytes = tex.EncodeToPNG();
tex.Compress(false);
string imagePath = "";
string name = System.DateTime.Now.ToString("yyyyMMddhhmmss") + ".png";
if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer)
imagePath = Application.persistentDataPath + "/ScreenShot";
else if (Application.platform == RuntimePlatform.WindowsPlayer)
imagePath = Application.dataPath + "/ScreenShot";
else if (Application.platform == RuntimePlatform.WindowsEditor)
{
imagePath = Application.dataPath;
imagePath = imagePath.Replace("/Assets", "ScreenShot");
}
imagePath = imagePath + "/" + name;
System.IO.File.WriteAllBytes(imagePath, imagebytes);
yield return new WaitForEndOfFrame();
//TODO
}
Unity3D-屏幕截图
最新推荐文章于 2020-09-15 09:49:25 发布