// Start is called before the first frame update IEnumerator AskDetection() { yield return(new WaitForEndOfFrame()); RenderTexture renderTexture = RenderTexture.GetTemporary(Screen.width, Screen.height, 24, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default, 1); ScreenCapture.CaptureScreenshotIntoRenderTexture(renderTexture); RenderTexture.active = renderTexture; txtDebug.text = "we bello hguaglio"; ScreenshotTexture.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0); ScreenshotTexture.Apply(); byte[] img = ScreenshotTexture.EncodeToJPG(); string url = baseurl + "predict/synth1"; List <IMultipartFormSection> data = new List <IMultipartFormSection>(); data.Add(new MultipartFormFileSection("image", img, "img.jpg", "image/jpeg")); UnityWebRequest request = UnityWebRequest.Post(url, data); yield return(request.SendWebRequest()); if (request.isNetworkError || request.isHttpError) { Debug.LogError(request.error); yield break; } JSONNode response = JSON.Parse(request.downloadHandler.text); txtDebug.text = response; }
private void Update() { if (Input.GetKeyDown(KeyCode.LeftShift) && Input.GetKeyDown(KeyCode.A)) { ScreenCapture.CaptureScreenshot($"{Application.dataPath}/Resources/Screenshoot.jpg"); m_ShortShoot = Resources.Load <Texture>("ScreenShoot"); } if (Input.GetKeyDown(KeyCode.LeftShift) && Input.GetKeyDown(KeyCode.S)) { m_ShortShoot = ScreenCapture.CaptureScreenshotAsTexture(0); } if (Input.GetKeyDown(KeyCode.LeftShift) && Input.GetKeyDown(KeyCode.D)) { RenderTexture renderTexture = new RenderTexture(720, 1280, 0); ScreenCapture.CaptureScreenshotIntoRenderTexture(renderTexture); m_ShortShoot = renderTexture; } if (Input.GetKeyDown(KeyCode.LeftShift) && Input.GetKeyDown(KeyCode.F)) { StartCoroutine(TScreenCapture()); } }
IEnumerator RecordFrame() { yield return(new WaitForEndOfFrame()); // Limit the amount of frames stored in memory if (m_Frames.Count >= m_MaxFrameCount) { m_RecycledRenderTexture = m_Frames.Dequeue(); } m_Time -= m_TimePerFrame; // Frame data RenderTexture rt = m_RecycledRenderTexture; m_RecycledRenderTexture = null; if (rt == null) { rt = new RenderTexture(m_Width, m_Height, 0, RenderTextureFormat.ARGB32); rt.wrapMode = TextureWrapMode.Clamp; rt.filterMode = FilterMode.Bilinear; rt.anisoLevel = 0; } ScreenCapture.CaptureScreenshotIntoRenderTexture(rt); m_Frames.Enqueue(rt); }
public IEnumerator UpdateScreenshotTexture() { yield return(new WaitForEndOfFrame()); ScreenCapture.CaptureScreenshotIntoRenderTexture(_renderTexture); ScreenshotTexture.ReadPixels(new Rect(0, 0, _renderTexture.width, _renderTexture.height), 0, 0); ScreenshotTexture.Apply(); byte[] bytes = ScreenshotTexture.EncodeToPNG(); string filename = ScreenShotName(m_ssRes.x, m_ssRes.y); if (System.IO.Directory.Exists(Application.dataPath + "/screenshots")) { System.IO.File.WriteAllBytes(filename, bytes); Debug.Log(string.Format("Took screenshot to: {0}", filename)); takeHiResShot = false; } else { System.IO.Directory.CreateDirectory(Application.dataPath + "/screenshots"); System.IO.File.WriteAllBytes(filename, bytes); Debug.Log(string.Format("Took screenshot to: {0}", filename)); takeHiResShot = false; } }
public int CaptureScreen(int id) { if (commandBuffer == null) { commandBuffer = new CommandBuffer(); commandBuffer.name = "ScreenCapture"; } commandBuffer.Clear(); for (int i = 0; i < FRAME_NUM; ++i) { if (!IsAvailable(i)) { continue; } frames[i].id = id; this.WriteToTagInfo(id, 0); this.WriteToTagInfoShort(Screen.width, 8); this.WriteToTagInfoShort(Screen.height, 10); Profiler.EmitFrameMetaData(ScreenShotToProfiler.MetadataGuid, ScreenShotToProfiler.InfoTag, tagInfo); var rt = RenderTexture.GetTemporary(Screen.width, Screen.height, 0, RenderTextureFormat.ARGB32); ScreenCapture.CaptureScreenshotIntoRenderTexture(rt); commandBuffer.BeginSample(CAPTURE_CMD_SAMPLE); commandBuffer.Blit(rt, frames[i].renderTexture); commandBuffer.EndSample(CAPTURE_CMD_SAMPLE); Graphics.ExecuteCommandBuffer(commandBuffer); RenderTexture.ReleaseTemporary(rt); commandBuffer.Clear(); return(i); } return(-1); }
protected internal override void NewFrameReady(RecordingSession session) { Profiler.BeginSample("GameViewInput.NewFrameReady"); ScreenCapture.CaptureScreenshotIntoRenderTexture(m_CaptureTexture); // Force opaque alpha channel and perform vertical flip if necessary MakeFullyOpaqueAndPerformVFlip(OutputRenderTexture); Profiler.EndSample(); }
public override void NewFrameReady(RecordingSession session) { Profiler.BeginSample("GameViewInput.NewFrameReady"); #if UNITY_2019_1_OR_NEWER ScreenCapture.CaptureScreenshotIntoRenderTexture(m_CaptureTexture); m_VFlipper?.Flip(m_CaptureTexture); #else readbackTexture = ScreenCapture.CaptureScreenshotAsTexture(); #endif Profiler.EndSample(); }
protected internal override void NewFrameReady(RecordingSession session) { Profiler.BeginSample("GameViewInput.NewFrameReady"); #if UNITY_2019_1_OR_NEWER ScreenCapture.CaptureScreenshotIntoRenderTexture(m_CaptureTexture); var movieRecorderSettings = session.settings as MovieRecorderSettings; bool needToFlip = scSettings.FlipFinalOutput; if (movieRecorderSettings != null) { bool encoderAlreadyFlips = movieRecorderSettings.encodersRegistered[movieRecorderSettings.encoderSelected].PerformsVerticalFlip; needToFlip &= encoderAlreadyFlips; } if (needToFlip) { OutputRenderTexture = m_VFlipper?.Flip(m_CaptureTexture); } // Force opaque alpha channel MakeFullyOpaque(OutputRenderTexture); #else ReadbackTexture = ScreenCapture.CaptureScreenshotAsTexture(); var movieRecorderSettings = session.settings as MovieRecorderSettings; if (movieRecorderSettings != null) { var currEncoder = movieRecorderSettings.encodersRegistered[movieRecorderSettings.encoderSelected]; var requiredFormat = currEncoder.GetTextureFormat(movieRecorderSettings); var isGameView = movieRecorderSettings.ImageInputSettings is GameViewInputSettings; if (!currEncoder.PerformsVerticalFlip) { ReadbackTexture = UnityHelpers.FlipTextureVertically(ReadbackTexture, movieRecorderSettings.CaptureAlpha); } if (requiredFormat != ReadbackTexture.format) { if (requiredFormat == TextureFormat.RGB24 && ReadbackTexture.format == TextureFormat.RGBA32) { ReadbackTexture = UnityHelpers.RGBA32_to_RGB24(ReadbackTexture); } else { throw new Exception($"Unexpected conversion requested: from {ReadbackTexture.format} to {requiredFormat}."); } } } // Force opaque alpha channel MakeFullyOpaque(ReadbackTexture); #endif Profiler.EndSample(); }
IEnumerator Start() { while (true) { yield return(new WaitForSeconds(1)); yield return(new WaitForEndOfFrame()); var rt = RenderTexture.GetTemporary(Screen.width, Screen.height, 0); ScreenCapture.CaptureScreenshotIntoRenderTexture(rt); AsyncGPUReadback.Request(rt, 0, TextureFormat.RGBA32, OnCompleteReadback); RenderTexture.ReleaseTemporary(rt); } }
IEnumerator SnapShot() { /* * This is the function that takes the photo. Turns the screenshot into * a texture that is then applied to the RawImage object. * NOTE! It is very important that thePhoto is disabled immediately after * because then this function will keep getting called as a coroutine and * it will basically turn into a horrible video feed lol * * The texture object is destroyed when the game is turned off via the * OnDisable() method inside Player_Space_Ship_Movement.cs. * Again, very important unless you like memory leaks. */ yield return(new WaitForEndOfFrame()); if (numPhotos == maxPhotos) { DebugText.text = "Out of Room!"; //galleryCanvas.SetActive(false); galleryCanvas.enabled = false; reticleCanvas.SetActive(true); nameCanvas.SetActive(true); StopCoroutine(SnapShot()); yield break; } thePhoto = photoGallery[i]; thePhoto.enabled = true; renderTexture = photoTextures[i]; renderTexture = new RenderTexture(Screen.width, Screen.height, 24, RenderTextureFormat.DefaultHDR); ScreenCapture.CaptureScreenshotIntoRenderTexture(renderTexture); thePhoto.texture = renderTexture; thePhoto.enabled = false; reticleCanvas.SetActive(true); nameCanvas.SetActive(true); i++; numPhotos++; galleryCanvas.enabled = false; //galleryCanvas.SetActive(false); /* * Texture2D texture = ScreenCapture.CaptureScreenshotAsTexture(); * thePhoto.texture = texture; * thePhoto.enabled = false; */ }
IEnumerator RecordScreenFrame() { while (true) { yield return(new WaitForEndOfFrame()); if (!connections.Any() || m_sendTexture == null || !m_sendTexture.IsCreated()) { continue; } ScreenCapture.CaptureScreenshotIntoRenderTexture(m_screenTexture); Graphics.Blit(m_screenTexture, m_sendTexture); } }
System.Collections.IEnumerator Start() { InitSendInstance(); InitConverter(); for (var eof = new WaitForEndOfFrame(); true;) { // Wait for the end of the frame. yield return(eof); // Request chain: Capture -> Convert -> Readback ScreenCapture.CaptureScreenshotIntoRenderTexture(_capture); RunConversion(); AsyncGPUReadback.Request(_converted, OnCompleteReadback); } }
public void UpdateScreenshotTexture(bool grayscale) { RenderTexture transformedRenderTexture = null; RenderTexture renderTexture = RenderTexture.GetTemporary( Screen.width, Screen.height, 24, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default, 1); try { ScreenCapture.CaptureScreenshotIntoRenderTexture(renderTexture); transformedRenderTexture = RenderTexture.GetTemporary( ScreenshotTexture.width, ScreenshotTexture.height, 24, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default, 1); Graphics.Blit( renderTexture, transformedRenderTexture, new Vector2(1.0f, -1.0f), new Vector2(0.0f, 1.0f)); RenderTexture.active = transformedRenderTexture; ScreenshotTexture.ReadPixels( new Rect(0, 0, ScreenshotTexture.width, ScreenshotTexture.height), 0, 0); } catch (Exception e) { Debug.Log("Exception: " + e); } finally { RenderTexture.active = null; RenderTexture.ReleaseTemporary(renderTexture); if (transformedRenderTexture != null) { RenderTexture.ReleaseTemporary(transformedRenderTexture); } } ScreenshotTexture.Apply(); }
private IEnumerator CaptureScreen() { yield return(new WaitForEndOfFrame()); int rtWidth = Screen.width; int rtHeight = Screen.height; if (previousFrameRT == null || previousFrameRT.width != rtWidth || previousFrameRT.height != rtHeight) { if (previousFrameRT != null) { Destroy(previousFrameRT); } previousFrameRT = new RenderTexture(rtWidth, rtHeight, 0); } ScreenCapture.CaptureScreenshotIntoRenderTexture(previousFrameRT); }
void Update() { // GameView capture mode if (_captureMethod == CaptureMethod.GameView) { PrepareBuffer(Screen.width, Screen.height); var temp = RenderTexture.GetTemporary(Screen.width, Screen.height, 0); ScreenCapture.CaptureScreenshotIntoRenderTexture(temp); Blitter.BlitVFlip(_resources, temp, _buffer, _keepAlpha); RenderTexture.ReleaseTemporary(temp); } // Texture capture mode if (_captureMethod == CaptureMethod.Texture) { if (_sourceTexture == null) { return; } PrepareBuffer(_sourceTexture.width, _sourceTexture.height); Blitter.Blit(_resources, _sourceTexture, _buffer, _keepAlpha); } // Camera capture mode if (_captureMethod == CaptureMethod.Camera) { PrepareCameraCapture(_sourceCamera); if (_sourceCamera == null) { return; } PrepareBuffer(_sourceCamera.pixelWidth, _sourceCamera.pixelHeight); } // Sender lazy initialization if (_sender == null) { _sender = new Sender(_spoutName, _buffer); } // Sender plugin-side update _sender.Update(); }
System.Collections.IEnumerator CaptureCoroutine() { for (var eof = new WaitForEndOfFrame(); true;) { // Wait for the end of the frame. yield return(eof); PrepareSenderObjects(); // Texture capture method if (captureMethod == CaptureMethod.Texture && sourceTexture != null) { var(w, h) = (sourceTexture.width, sourceTexture.height); // Pixel format conversion var buffer = _converter.Encode(sourceTexture, keepAlpha, true); // Readback entry allocation and request _pool.NewEntry(w, h, keepAlpha, metadata) .RequestReadback(buffer, _onReadback); } // Game View capture method if (captureMethod == CaptureMethod.GameView) { // Game View screen capture with a temporary RT var(w, h) = (Screen.width, Screen.height); var tempRT = RenderTexture.GetTemporary(w, h, 0); ScreenCapture.CaptureScreenshotIntoRenderTexture(tempRT); // Pixel format conversion var buffer = _converter.Encode(tempRT, keepAlpha, false); RenderTexture.ReleaseTemporary(tempRT); // Readback entry allocation and request _pool.NewEntry(w, h, keepAlpha, metadata) .RequestReadback(buffer, _onReadback); } } }
protected internal override void NewFrameReady(RecordingSession session) { Profiler.BeginSample("GameViewInput.NewFrameReady"); ScreenCapture.CaptureScreenshotIntoRenderTexture(m_CaptureTexture); var movieRecorderSettings = session.settings as MovieRecorderSettings; bool needToFlip = scSettings.FlipFinalOutput; if (movieRecorderSettings != null) { bool encoderAlreadyFlips = movieRecorderSettings.encodersRegistered[movieRecorderSettings.encoderSelected].PerformsVerticalFlip; needToFlip &= encoderAlreadyFlips; } if (needToFlip) { OutputRenderTexture = m_VFlipper?.Flip(m_CaptureTexture); } // Force opaque alpha channel MakeFullyOpaque(OutputRenderTexture); Profiler.EndSample(); }
ComputeBuffer CaptureImmediate() { PrepareInternalObjects(); // Texture capture method // Simply convert the source texture and return it. if (_captureMethod == CaptureMethod.Texture) { if (_sourceTexture == null) { return(null); } _width = _sourceTexture.width; _height = _sourceTexture.height; return(_converter.Encode(_sourceTexture, _enableAlpha)); } // Game View capture method // Capture the screen into a temporary RT, then convert it. if (_captureMethod == CaptureMethod.GameView) { _width = Screen.width; _height = Screen.height; var tempRT = RenderTexture.GetTemporary(_width, _height, 0); ScreenCapture.CaptureScreenshotIntoRenderTexture(tempRT); var converted = _converter.Encode(tempRT, _enableAlpha); RenderTexture.ReleaseTemporary(tempRT); return(converted); } Debug.LogError("Wrong capture method."); return(null); }
IEnumerator Test1() { //Debug.LogError("one"); while (true) { //yield return new WaitForSeconds(1); // yield return new WaitForEndOfFrame(); var rt = RenderTexture.GetTemporary(Screen.width, Screen.height, 0, RenderTextureFormat.ARGB32); ScreenCapture.CaptureScreenshotIntoRenderTexture(rt); System.Diagnostics.Stopwatch wTime = new System.Diagnostics.Stopwatch(); wTime.Start(); var req = AsyncGPUReadback.Request(rt, 0, TextureFormat.ARGB32); yield return(new WaitUntil(() => req.done)); wTime.Stop(); Debug.LogError("reqeust time :" + wTime.ElapsedTicks / 10000.0f + "ms"); //var colorArray = req.GetData<Color32>().ToArray(); var tex = new Texture2D(Screen.width, Screen.height, TextureFormat.ARGB32, false); tex.LoadRawTextureData(req.GetData <uint>()); tex.Apply(); File.WriteAllBytes(@"D:\test\test" + curRequestIndex + ".png", ImageConversion.EncodeToPNG(tex)); RenderTexture.ReleaseTemporary(rt); Destroy(tex); curRequestIndex++; Debug.LogError(curRequestIndex); if (curRequestIndex == 100) { yield break; } Debug.LogError("after:" + curRequestIndex); } }
// void OnPreRender () { // this.camRect = this.camera.rect; // // this.scaledRect.Set(this.rectRead.x, this.rectRead.y, this.rectRead.width, this.rectRead.height); // this.camera.rect = this.scaledRect; // // Read screen image into render texture // this.renderTexture = new RenderTexture(this.width, this.height, 0, RenderTextureFormat.ARGB32); // ScreenCapture.CaptureScreenshotIntoRenderTexture(this.renderTexture); // } // void OnRenderImage (RenderTexture src, RenderTexture dest) { // this.camera.rect = this.camRect; // src.filterMode = this.filterMode; // Graphics.Blit(src, dest); // } IEnumerator Start() { // this.width = Screen.width; // this.height = Screen.height; int divWidth = this.width / divisions; int divHeight = this.height / divisions; Debug.LogFormat("width: {0}, height: {1}", divWidth, divHeight); while (!Teleportal.Teleportal.tp.IsConnected() || !Teleportal.AuthModule.Shared.IsAuthed()) { // Wait for connection yield return(new WaitForSeconds(0.2f)); } while (Teleportal.Teleportal.tp.IsConnected()) { // Wait for the specified delay yield return(new WaitForSeconds(this.NetworkInterval)); if (!this.screenTxEnabled) { continue; } yield return(new WaitForEndOfFrame()); // Read screen image into render texture this.renderTexture = new RenderTexture(this.width, this.height, 0, RenderTextureFormat.ARGB32); ScreenCapture.CaptureScreenshotIntoRenderTexture(this.renderTexture); // Async read bytes operation // AsyncGPUReadback.Request(this.renderTexture, 0, TextureFormat.ARGB32, this.ReadbackCompleted); RenderTexture.active = this.renderTexture; this.byteArrs = new List <byte[]>(); this.byteArrLen = 0; for (int i = 0; i < divisions; i++) { int x = divWidth * i; int y = divHeight * i; Debug.LogFormat("width_height {0} {1} x_y {2} {3}", width, height, x, y); this.t2d = new Texture2D(divWidth, divHeight, TextureFormat.ARGB32, false); this.rectRead = new Rect(x, y, divWidth, divHeight); Debug.Log(Camera.main.rect); this.t2d.ReadPixels(this.rectRead, 0, 0); // this.t2d.Compress(false); this.t2d.Apply(); byte[] tmp = t2d.GetRawTextureData <byte>().ToArray(); this.byteArrs.Add(tmp); byteArrLen += tmp.Length; yield return(new WaitForSeconds(this.divisionInterval)); } RenderTexture.active = null; Thread t = new Thread(this.ByteArrayToString); t.Start(null);//ba); } }
private IEnumerator VideoRecoder() { while (isFinish == false) { yield return(new WaitForEndOfFrame()); if (isPlay == false) { continue; } if (isPause == false) { frameCount--; } if (frameCount >= 0 || isAsyncGPUReadBackFinish == false) { continue; } if (isFinish == true) { break; } switch (captureMode) { #if UNITY_2019_1_OR_NEWER case CaptureMode.AsyncGPUReadBack: { if ( (textureHeader == null) || (renderTexture == null) || (renderTexture.width != Screen.currentResolution.width) || (renderTexture.height != Screen.currentResolution.height) ) { if (renderTexture != null) { renderTexture.Release(); Destroy(renderTexture); } renderTexture = new RenderTexture( Screen.currentResolution.width, Screen.currentResolution.height, 0 ); var header = new TextureHeader(renderTexture.width, renderTexture.height, TextureFormat.RGBA32, false, true); var bf = new BinaryFormatter(); var ms = new MemoryStream(); try { bf.Serialize(ms, header); PlayerConnection.instance.Send(PlayerView.kMsgSendPlayerToEditorHeader, ms.ToArray()); } finally { ms.Close(); } textureHeader = header; } frameCount = frameCountMax; isAsyncGPUReadBackFinish = false; ScreenCapture.CaptureScreenshotIntoRenderTexture(renderTexture); AsyncGPUReadback.Request(renderTexture, 0, TextureFormat.RGBA32, ReadbackCompleted); } break; case CaptureMode.Normal: #else default: #endif { var texture2D = ScreenCapture.CaptureScreenshotAsTexture(); var header = new TextureHeader(texture2D.width, texture2D.height, TextureFormat.RGBA32, false, false); if (textureHeader == null || textureHeader != header) { var bf = new BinaryFormatter(); var ms = new MemoryStream(); try { bf.Serialize(ms, header); PlayerConnection.instance.Send(PlayerView.kMsgSendPlayerToEditorHeader, ms.ToArray()); } finally { ms.Close(); } textureHeader = header; } PlayerConnection.instance.Send( PlayerView.kMsgSendPlayerToEditor, texture2D.GetRawTextureData() ); Destroy(texture2D); frameCount = frameCountMax; } break; } } }
/// <summary> /// Get path to game screenshot when exception occured /// </summary> /// <returns>Path to game screenshot</returns> private string GetScreenshotPath(string dataPrefix) { if (!_settings.GenerateScreenshotOnException) { return(string.Empty); } var screenshotPath = Path.Combine(_settings.DatabasePath, string.Format("{0}-screen.jpg", dataPrefix)); lock (_lock) { if (BacktraceDatabase.LastFrameTime == _lastScreenTime) { if (File.Exists(_lastScreenPath)) { File.Copy(_lastScreenPath, screenshotPath); return(screenshotPath); } return(_lastScreenPath); } else { Texture2D result; if (ScreenshotMaxHeight < Screen.height) { float ratio = Screen.width / Screen.height; int targetHeight = Mathf.Min(Screen.height, ScreenshotMaxHeight); int targetWidth = Mathf.RoundToInt(targetHeight * ratio); #if UNITY_2019_1_OR_NEWER RenderTexture screenTexture = RenderTexture.GetTemporary(Screen.width, Screen.height); ScreenCapture.CaptureScreenshotIntoRenderTexture(screenTexture); #else Texture2D screenTexture = ScreenCapture.CaptureScreenshotAsTexture(); #endif // Create a render texture to render into RenderTexture rt = RenderTexture.GetTemporary(targetWidth, targetHeight); if (SystemInfo.graphicsUVStartsAtTop) { Graphics.Blit(screenTexture, rt, new Vector2(1.0f, -1.0f), new Vector2(0.0f, 1.0f)); } else { Graphics.Blit(screenTexture, rt); } RenderTexture previousActiveRT = RenderTexture.active; RenderTexture.active = rt; // Create a texture & read data from the active RenderTexture result = new Texture2D(targetWidth, targetHeight, TextureFormat.RGB24, false); result.ReadPixels(new Rect(0, 0, targetWidth, targetHeight), 0, 0); result.Apply(); // Reset to initial state RenderTexture.active = previousActiveRT; RenderTexture.ReleaseTemporary(rt); #if UNITY_2019_1_OR_NEWER RenderTexture.ReleaseTemporary(screenTexture); #else GameObject.Destroy(screenTexture); #endif } else { result = ScreenCapture.CaptureScreenshotAsTexture(); } File.WriteAllBytes(screenshotPath, result.EncodeToJPG(ScreenshotQuality)); GameObject.Destroy(result); _lastScreenTime = BacktraceDatabase.LastFrameTime; _lastScreenPath = screenshotPath; } } return(screenshotPath); }