Unity3D-屏幕截图

来源:互联网 发布:手机屏幕写字的软件 编辑:程序博客网 时间:2024/06/11 11:00
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     }
0 0