unity截屏保存 iOS 安卓 完美使用

第一种方式:


 public void Capture()
    {
        Application.CaptureScreenshot ("ScreenShot.png",0);
    }



第二种方式:

unity截屏保存 iOS 安卓 完美使用


第三种方式:


 void Capture2()
    {
        CaptureCamera(Camera.main, new Rect(Screen.width * 0f, Screen.height * 0f, Screen.width * 1f, Screen.height * 1f));

    }

    void CaptureCamera(Camera camera, Rect rect)
    {

        RenderTexture rt = new RenderTexture((int)rect.width, (int)rect.height, 0);

        camera.targetTexture = rt;
        camera.Render();

        RenderTexture.active = rt;
        Texture2D screenShot = new Texture2D((int)rect.width, (int)rect.height, TextureFormat.RGB24, false);
        screenShot.ReadPixels(rect, 0, 0);
        screenShot.Apply();

        camera.targetTexture = null;

        RenderTexture.active = null;
        GameObject.Destroy(rt);
        byte[] bytes = screenShot.EncodeToPNG();
        string filename = Application.dataPath + "/Screenshot.png";
        System.IO.File.WriteAllBytes(filename, bytes);
    }