Capture and save screenshot with ScreenCapture.CaptureScreenshot

前端 未结 3 585
感动是毒
感动是毒 2021-01-15 19:14

I\'ve been trying to take a screenshot and then immediately after, use it to show some sort of preview and some times it works and some times it doesn\'t, I\'m currently not

3条回答
  •  鱼传尺愫
    2021-01-15 19:19

    I see nothing in the docs that says its not Async. In fact, for Android (if I'm reading this correctly), it explicitly says it's async.

    That said, I'd try stalling while the file is not found. Throw it in a coroutine and

    FileInfo yourFile = new FileInfo("YourFile.png");
    while (File.Exists(yourFile.name) || IsFileLocked(yourFile)) 
        yield return null;
    

    IsFileLocked

    You could also try throwing in some debug checks in there to see how long it takes (seconds or frames) before the file appears (assuming it ever appears).

    Edit: As derHugo pointed out, the file existing doesn't mean the file is ready yet. I have edited the code to handle that! But it still doesn't cover the case where the file already existed, in which case you probably want a dynamic file name like with a timestamp, or you want to delete the file first!

提交回复
热议问题