示例#1
0
    public static IEnumerator saveRenderTexture()
    {
        CommonFunc.AllHideUI();
        // We should only read the screen after all rendering is complete
        yield return(new WaitForEndOfFrame());

        // Create a texture the size of the screen, RGB24 format
        int       width  = Screen.width;
        int       height = Screen.width;
        Texture2D tex    = new Texture2D(width, height, TextureFormat.RGB24, false);

        // Read screen contents into the texture
        tex.ReadPixels(new Rect(0, 70, width, height), 0, 0);
        tex.Apply();

        // Encode texture into PNG
        byte[] bytes = tex.EncodeToPNG();
        Destroy(tex);
        yield return(0);

        File.WriteAllBytes("capture.png", bytes);

        CommonFunc.AllViewUI();
    }