Search code examples
androidunity-game-enginearcore

How to take & save picture / screenshot using Unity ARCore SDK?


I found the answer to how to do it natively here but Im running Unity.

How to take picture with camera using ARCore

I'm not sure how to access the Unity surface renderer thread to be able to drop in those functions.

This looks like a good start. Ideas?

Edit:

Using Texture2d ReadPixels or ScreenCapture.CaptureScrenshot are not viable as they are blocking the render thread. The code below is enough to block the thread.

StartCoroutine(TakeScreenshot());

private IEnumerator TakeScreenshot()
    {
        yield return new WaitForEndOfFrame();

        Texture2D ss = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
        ss.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
        ss.Apply();

Edit 2: Am considering using this technique. Will report back if successful.


Solution

  • ARCore provides its own TextureReader class that is extremely fast and doesn't reproduce the side effects noted. TextureReader_acquireFrame

    https://github.com/google-ar/arcore-unity-sdk/blob/master/Assets/GoogleARCore/Examples/ComputerVision/Scripts/TextureReaderApi.cs