コード例 #1
0
    public IEnumerator CaptureScreenshotsNew_ColorOnly()
    {
        var requests = new List <AsyncRequest <CaptureCamera.CaptureState> >();

        SetupTest(1000, 3);

        yield return(null);

        for (int i = 0; i < kNumFramesToRender; ++i)
        {
            for (int c = 0; c < _cameras.Length; ++c)
            {
                var camera = _cameras[c];

                var r = CaptureCamera.CaptureColorToFile(
                    camera,
                    GraphicsFormat.R8G8B8A8_UNorm,
                    string.Format("test_capture_{0}_camera_{1}_color.jpg", i, c));

                requests.Add(r);

                camera.Render();
            }

            yield return(null);
        }

        Debug.Log("Finally, wait for any remaining requests to complete.");

        if (requests.Exists(r => r.completed == false))
        {
            yield return(null);
        }

        for (var i = 0; i < requests.Count; ++i)
        {
            if (requests[i].error)
            {
                Debug.Log(string.Format("Request {0} returned error.", i));
            }
        }

        Debug.Assert(!requests.Exists(r => r.error == true));

        Debug.Log("CaptureScreenshotsNew_ColorOnly elapsed " + Elapsed());
    }
コード例 #2
0
    IEnumerator CaptureColorAndEnsureUpright(bool fastPath)
    {
        var camera = SetupCameraWithRenderTexture(2, 2, GraphicsFormat.R8G8B8A8_UNorm);

        var imagePath = Path.Combine(Application.persistentDataPath, "upright.png");

        var useAsyncReadbackIfSupported = CaptureOptions.useAsyncReadbackIfSupported;

        CaptureOptions.useAsyncReadbackIfSupported = fastPath;

        var request = CaptureCamera.CaptureColorToFile(camera, GraphicsFormat.R8G8B8A8_UNorm, imagePath, CaptureImageEncoder.ImageFormat.Png);

        var plane1 = CreatePlaneInFrontOfCamera(Color.black, .1f);

        //position on the bottom half of the screen, in front of plane2
        plane1.transform.localPosition = new Vector3(0, -.5f, .5f);
        plane1.transform.localScale    = new Vector3(1, -1f, .1f);
        var plane2 = CreatePlaneInFrontOfCamera(Color.red);

        plane2.transform.localPosition = new Vector3(0, 0, 1f);
        plane2.transform.localScale    = new Vector3(1, -1f, 1f);

        camera.clearFlags = CameraClearFlags.Nothing;
        camera.Render();

        while (!request.completed)
        {
            yield return(null);
        }

        CaptureOptions.useAsyncReadbackIfSupported = useAsyncReadbackIfSupported;

        Assert.True(request.error == false);

        var texture = new Texture2D(2, 2, TextureFormat.RGB24, false);

        texture.LoadImage(File.ReadAllBytes(imagePath));

        Assert.True(CompareColors(texture.GetPixel(0, 0), Color.black));
        Assert.True(CompareColors(texture.GetPixel(1, 0), Color.black));
        Assert.True(CompareColors(texture.GetPixel(0, 1), Color.red));
        Assert.True(CompareColors(texture.GetPixel(1, 1), Color.red));
    }