LoadRawTextureData() 没有足够的数据在 Unity 中提供错误 [英] LoadRawTextureData() not enough data provided error in Unity

查看:61
本文介绍了LoadRawTextureData() 没有足够的数据在 Unity 中提供错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am working on a project using ARcore.

我需要一个在 ARcore 相机上可见的真实世界屏幕,以前使用擦除 UI 和捕获的方法.

I need a real world screen that is visible on the ARcore camera, formerly using the method of erasing UI and capturing.

但是太慢了以至于我在 Arcore API 中找到了 Frame.CameraImage.Texture

But it was so slow that I found Frame.CameraImage.Texture in Arcore API

它在 Unity Editor 环境中正常工作.

It worked normally in a Unity Editor environment.

但是如果您在手机上构建它并检查它,Texture 为空.

But if you build it on your phone and check it out, Texture is null.

Texture2D snap = (Texture2D)Frame.CameraImage.Texture;

是什么原因?可能是CPU问题?

What is the reason? maybe CPU problem?

我尝试做一个不同的功能.

and I tried to do a different function.

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;

        }
    }
}

但是如果我改变纹理格式,它就会出来.

But if I change the texture format, it will come out.

private TextureFormat _format = TextureFormat.R8;

这是可行的,但我不想要红色图像,我想要 rgb 颜色

it is work, but i don't want to red color image, i want to rgb color

我该怎么办?

推荐答案

R8 只是红色数据.您可以使用 TextureFormat.RGBA32,并像这样设置缓冲区:

R8 Just red data. You can use TextureFormat.RGBA32, and set buffer like this:

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

这篇关于LoadRawTextureData() 没有足够的数据在 Unity 中提供错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆