Unity3D黑屏截图

时间:2016-01-22 10:39:34

标签: c# image unity3d texture2d unity5

我正在使用

截取屏幕截图
Texture2D tex = new Texture2D(width,height);
Rect textureRect = new Rect(0,0,width,height);
tex.ReadPixels(textureRect,0,0);
tex.Apply();

工作正常。但是当我在相机上应用图像效果(如Unity Standard Assets中提供的模糊或绽放)时,捕获的屏幕截图为黑色。我不懂为什么。有人可以帮我这个吗?

3 个答案:

答案 0 :(得分:1)

使用Application.CaptureScreenshot截取屏幕截图。

Application.CaptureScreenshot("Screenshot.png");

如果您想要显示游戏,我建议使用RenderTexture,我认为自Unity5以来可以免费使用。{/ p>

答案 1 :(得分:0)

您应该尝试在任何组件的OnPostRender()上调用它。

您还可以在Camera.OnRenderImage(RenderTexture,RenderTexture)

中运行捕获代码

完成所有渲染后,Unity3D引擎调用此方法,我们在屏幕上显示finall图像。

您需要为其创建组件并将其附加到相机。

http://docs.unity3d.com/ScriptReference/Camera.OnRenderImage.html

答案 2 :(得分:0)

public IEnumerator SaveScreenshotRoutine(float width, float height, Action<Texture2D> result)
{
    yield return new WaitForEndOfFrame();
    var tex = new Texture2D( width, height, TextureFormat.RGB24, false );
    tex.ReadPixels( new Rect(0,0,width, height), 0, 0 );
    tex.Apply();
    result(tex);
}

你等待框架完全完成,所以即使渲染已经完成,任何活动/非活动对象已被添加/删除,你将它用作:

Texture2D texture = null;
StartCoroutine(SaveScreenshotRoutine(result => texture =result));