Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# GetRawTextureData返回字节[0]_C#_Android_Unity3d_Agora.io - Fatal编程技术网

C# GetRawTextureData返回字节[0]

C# GetRawTextureData返回字节[0],c#,android,unity3d,agora.io,C#,Android,Unity3d,Agora.io,我正在尝试构建一个Unity应用程序,它通过Agora.io视频通话从插入Android手机的USB摄像头发送视频提要。我正在使用Unity资产: 该资源有一个名为GetFrame()的方法,我使用该方法获取每个帧,并通过Agora.io以字节[]数组的形式发送。在发送之前,我需要将GetFrame()返回的Texture2D转换为字节[]。问题是Unity的Texture2D.GetRawTextureData()方法返回的是一个空字节数组。当输出到场景中的面板时,Texture2D不为nu

我正在尝试构建一个Unity应用程序,它通过Agora.io视频通话从插入Android手机的USB摄像头发送视频提要。我正在使用Unity资产:

该资源有一个名为GetFrame()的方法,我使用该方法获取每个帧,并通过Agora.io以字节[]数组的形式发送。在发送之前,我需要将GetFrame()返回的Texture2D转换为字节[]。问题是Unity的Texture2D.GetRawTextureData()方法返回的是一个空字节数组。当输出到场景中的面板时,Texture2D不为null,纹理显示良好。还有别的办法吗?我可能做错了什么

while (!usbStopped)
{
    tempTexture2D = usbCamera.GetFrame(0);
    byte[] bytes = tempTexture2D.GetRawTextureData();
    
    if (bytes.Length == 0)
        throw new Exception("Frame bytes empty!");

    yield return StartCoroutine(PushFrame(bytes, 640, 480, () => bytes = null);
}
例外总是被击中。非常感谢您的帮助。

GetRawTextureData()应该适用于Texture2D实例,我以前已经测试过。获得0长度的可能原因可能来自该纹理的渲染器。有没有一种方法可以检查usbCamera.GetFrame(0)调用是否实际返回了一些内容?是否需要先设置渲染器?也请考虑下面的描述:


纹理可能不可读。您是否查看过这样的帖子:
Also note that the system memory copy might not match what is in the GPU texture data at the moment. For example, after calling SetPixels the system memory copy is already modified, but the GPU copy will only match after calling Apply(). Some cases of Graphics.CopyTexture might be copying only the GPU texture side (e.g. copying from a RenderTexture into a Texture2D), and this will not be reflected in GetRawTextureData contents.