renderTexture | 将填充屏幕内容的 RenderTexture。 |
将游戏视图的屏幕截图捕获到 RenderTexture 对象中。
这种屏幕截图变体使您能够使用 AsyncGPUReadback 异步读取像素,从而使该过程在主线程上占用更少的时间。
有关何时调用此方法的信息,请参阅 ScreenCapture.CaptureScreenshotAsTexture 中的说明。
using UnityEngine; using System.Collections; using UnityEngine.Rendering;
public class ScreenCaptureIntoRenderTexture : MonoBehaviour { private RenderTexture renderTexture;
IEnumerator Start() { yield return new WaitForEndOfFrame();
renderTexture = new RenderTexture(Screen.width, Screen.height, 0); ScreenCapture.CaptureScreenshotIntoRenderTexture(renderTexture); AsyncGPUReadback.Request(renderTexture, 0, TextureFormat.RGBA32, ReadbackCompleted); }
void ReadbackCompleted(AsyncGPUReadbackRequest request) { // Render texture no longer needed, it has been read back. DestroyImmediate(renderTexture);
using (var imageBytes = request.GetData<byte>()) { // do something with the pixel data. } } }