我想从Unity3d虚拟相机中抓取帧,然后让它们显示在另一个原始图像上。结果是原始图像屏幕非常闪烁。
using UnityEngine;
using UnityEngine.UI;
public class RawImageVirtualWebCamTexture : MonoBehaviour
{
private RawImage rawimage;
void Start()
{
GameObject obj = GameObject.Find("RawImageTransform");
rawimage = obj.GetComponent<RawImage>();
}
void OnRenderImage(RenderTexture source, RenderTexture destination)
{
if (source != null)
{
rawimage.texture = source;
}
Graphics.Blit(source, destination);
}
}
我想看到流畅的画面。但是该怎么做呢?
最佳答案
如果它是关于 Unity Camera
的,则您无需捕获任何内容。
只需创建一个新的 RenderTexture
Assets
-> 右键单击 -> Create
-> RenderTexture
让您的 Camera
渲染到 RenderTexture
中,而不是通过简单地引用 Target Texture< 中创建的
(这使得此 RenderTexture
来渲染游戏 View Camera
不再渲染到游戏 View ,而是渲染到引用的 RenderTexture
)
最后简单地使用创建的 RenderTexture
作为 RawImage
的 Texture
如果您需要那个 Camera
同时渲染到正常的游戏 View ,只需在上述过程的子对象上使用另一个 Camera
。
结果
关于unity3d - 如何从Unity3d摄像头抓取帧并实时显示在另一个rawImage上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56783654/