Take a screenshot

I want to take a screenshot and then perform a OCRrequest to Google Cloud Vision in C#. Currently I am having problems in the part of taking the screenshot. Locally it works, but in zapworks I recieve next error “An abnormal situation has occurred: the PlayerLoop internal function has been called recursively”. Is there a suggested way of of taking a screenshot that works in zapworks? My code is as follows:

public async Task TakeScreenshotAsync()

{
    string filename = "screenshot.png";

    ScreenCapture.CaptureScreenshot(filename);

    // Wait for the screenshot to be saved
    Thread.Sleep(500);

    // Read the saved screenshot file
    byte[] bytes = File.ReadAllBytes(filename);

    // await SendOCRRequest(bytes);

}

Hello @luis95.garay

The Unitys’ CaptureScreenshot method saves the file at the designated path, which will not work on web because there is no file system access available to browsers! For obvious security reasons and hence you get the exception.

You may want to try our WebGL Save and Share package, though for accessing the byte[] for screen data you can take reference from this Snapshot method that I’ve implemented and pass that on to your destination.

Hope that helps.

Best,