using System; using System.Collections; using UnityEngine; using UnityEngine.Rendering; public class TakeScreenShots : MonoBehaviour { static Byte[] _bytes; static RenderTexture renderTexture; public static IEnumerator FromScreen(string Category) { //Set Scene camera // _handler.Close2DPlan(); // DASH.HDsetBTNcolor(true); // ReturnCameraToInitialPosition(); //Render yield return new WaitForEndOfFrame(); renderTexture = new RenderTexture(Screen.width, Screen.height, 0); ScreenCapture.CaptureScreenshotIntoRenderTexture(renderTexture); AsyncGPUReadback.Request(renderTexture, 0, TextureFormat.RGBA32, ReadbackCompleted); //yield return _bytes; //_bytes; } static void ReadbackCompleted(AsyncGPUReadbackRequest request) { // Render texture no longer needed, it has been read back. var format = renderTexture.graphicsFormat; uint width = (uint)renderTexture.width; uint height = (uint)renderTexture.height; DestroyImmediate(renderTexture); using (var imageBytes = request.GetData()) { var bytes = ImageConversion.EncodeArrayToPNG(imageBytes.ToArray(), format, width, height); string stringifiedPNG = Convert.ToBase64String(bytes); //this.Emit("screenShot", stringifiedPNG); DASH.HDsetBTNcolor(false); _bytes = bytes; } //return _bytes; } }