C# LoadRawTextureData()提供的数据不足Unity中出现错误

C# LoadRawTextureData()提供的数据不足Unity中出现错误,c#,unity3d,arcore,texture2d,C#,Unity3d,Arcore,Texture2d,我正在使用ARcore进行一个项目 我需要一个在ARcore摄像头上可见的真实屏幕,以前使用擦除UI和捕获的方法 但是速度太慢了,我在Arcore API中找到了Frame.CameraImage.Texture 它在Unity编辑器环境中正常工作 但如果你在手机上构建并检查它,纹理是空的 Texture2D snap = (Texture2D)Frame.CameraImage.Texture; 原因是什么?也许是CPU问题 我试着做一个不同的功能 public class TestFram

我正在使用ARcore进行一个项目

我需要一个在ARcore摄像头上可见的真实屏幕,以前使用擦除UI和捕获的方法

但是速度太慢了,我在Arcore API中找到了Frame.CameraImage.Texture

它在Unity编辑器环境中正常工作

但如果你在手机上构建并检查它,纹理是空的

Texture2D snap = (Texture2D)Frame.CameraImage.Texture;
原因是什么?也许是CPU问题

我试着做一个不同的功能

public class TestFrameCamera : MonoBehaviour
{
    private Texture2D _texture;
    private TextureFormat _format = TextureFormat.RGBA32;

    // Use this for initialization
    void Start()
    {
        _texture = new Texture2D(Screen.width, Screen.height, _format, false, false);
    }

    // Update is called once per frame
    void Update()
    {

        using (var image = Frame.CameraImage.AcquireCameraImageBytes())
        {
            if (!image.IsAvailable) return;

            int size = image.Width * image.Height;
            byte[] yBuff = new byte[size];
            System.Runtime.InteropServices.Marshal.Copy(image.Y, yBuff, 0, size);

            _texture.LoadRawTextureData(yBuff);
            _texture.Apply();

            this.GetComponent<RawImage>().texture = _texture;

        }
    }
}
这是工作,但我不想红色的图像,我想rgb颜色

我该怎么办


R8
只有红色数据。 您可以使用
TextureFormat.RGBA32
,并按如下方式设置缓冲区:

IntPtr _buff = Marshal.AllocHGlobal(width * height*4);

R8
只有红色数据。 您可以使用
TextureFormat.RGBA32
,并按如下方式设置缓冲区:

IntPtr _buff = Marshal.AllocHGlobal(width * height*4);

谢谢你的回答。但我已经解决了这个问题,在我的例子中,我将bufferize指定为width*height*3/2,并且成功地将YUV420SP格式转换为RGBA32格式。谢谢您的回答。但我已经解决了这个问题,在我的例子中,我将bufferize指定为width*height*3/2,并且成功地将YUV420SP格式转换为RGBA32格式。