方法一:也是比较常见的方法,把摄像头的target Texture设置为一个rendertexture,然后读取像素到一个texture2d上,在在texture2d上获取得到图片字节。
优点:简单明了
缺点:ReadPixels + GetRawTextureData 经测试,需要耗时10-20ms左右,会降低FPS.
yield return new WaitForEndOfFrame();
if (depthCamera.targetTexture == null)
{
_tempRT = new RenderTexture(_width, _height, 24, GetTargetFormat(depthCamera));
//_tempRT.antiAliasing = GetAntiAliasingLevel(depthCamera);
depthCamera.targetTexture = _tempRT;
_screenShot = new Texture2D(_tempRT.width, _tempRT.height, TextureFormat.RGBA32, false);
}
RenderTexture.active = _tempRT;
_screenShot.ReadPixels(new Rect(0, 0, _tempRT.width, _tempRT.height), 0, 0);
_screenShot.Apply();
RenderTexture.active = null;
//string fileName = "test1234.png";
//System.IO.File.WriteAllBytes(fileName, _screenShot.EncodeToPNG());
btyes videoBytes = _screenShot.GetRawTextureData();
//对videoBytes进行编码,发送到客户端
encode(videoBytes);
方案二:利用Unity 提供的一个GPUReadBack的方法获取图片数据,经测试,这个方法没有显著的提高效率。
void remoteRender2(msgStrcut msgCmd)
{
if (depthCamera.targetTexture == null)
{
_tempRT = new RenderTexture(_width, _height, 24,
400


并编码发送以及性能测试&spm=1001.2101.3001.11974&articleId=109473476&d=1&t=3&u=95355c53a0eb4ff3a5da3e0aecf3a79c)

被折叠的 条评论
为什么被折叠?



