Taking camera snapshot with "TryGetLatestImage"

I have couple of questions regarding how TryGetLatestImage works…

  1. I have “TakeSnapshot” method connected with button (onclick). When i click the button first time it doesn’t go inside “arCameraManager.TryGetLatestImage(out cameraImage)”. Second time it works.
private void TakeSnapshot() {
            XRCameraImage cameraImage;

            if (arCameraManager.TryGetLatestImage(out cameraImage)) {
                StartCoroutine(ProcessImage(cameraImage));
                cameraImage.Dispose();
            }
        }

        IEnumerator ProcessImage(XRCameraImage image) {
            var request = image.ConvertAsync(new XRCameraImageConversionParams {
                inputRect = new RectInt(0, 0, image.width, image.height),
                    outputDimensions = new Vector2Int(image.width, image.height),
                    outputFormat = TextureFormat.RGB24,
                    transformation = CameraImageTransformation.MirrorY
            });

            while (!request.status.IsDone())
                yield return null;

            if (request.status != AsyncCameraImageConversionStatus.Ready) {
                Debug.LogErrorFormat("Request failed with status {0}", request.status);
                request.Dispose();
                yield break;
            }

            var rawData = request.GetData<byte>();

            Texture2D imageTexture = new Texture2D(
                request.conversionParams.outputDimensions.x,
                request.conversionParams.outputDimensions.y,
                request.conversionParams.outputFormat,
                false);

            imageTexture.LoadRawTextureData(rawData);
            imageTexture.Apply();

            request.Dispose();

            snapshotImage.texture = imageTexture;
        }
  1. Texture is 640x480 and rotated (landscape instead of portrait). How can i set resolution to native and rotate it?

  2. If i use “arCameraManager.frameReceived” resolution is correct, but this is not useful, cause frame is received every frame (i think).

private void OnEnable() {
            arCameraManager.frameReceived += OnFrameReceived;
        }

        private void OnFrameReceived(ARCameraFrameEventArgs obj) {
            var tex = obj.textures[0];
        }

Help please :slight_smile: … Thank you

Bytheway code is from official help: Accessing the device camera image on the CPU | AR Foundation | 4.0.12
I have “TakeSnapshot” instead of “GetImageAsync”…
I think that TryGetLatestImage is async (it doesn’t receive image on the same frame). But if that is true, you must call “GetImageAsync” at least 2 times… Which is wierd.
I’m confused here.

Edit:
I also updated ARFoundation, subsytem and ARCore, and i used:
arCameraManager.TryAcquireLatestCpuImage(out XRCpuImage cameraImage)
… no difference.