设置:Unity 2019
我正在尝试从平面上获取纹理。
我捕获相机输入并将其映射到平面上。然后,我想连续读取纹理。
我尝试过类似的操作。 PS:我是团结的新人。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraInput : MonoBehaviour
{
static WebCamTexture backCam;
void Start()
{
if (backCam == null)
backCam = new WebCamTexture();
GetComponent<Renderer>().material.mainTexture = backCam;
if (!backCam.isPlaying)
backCam.Play();
}
void Update()
{
byte[] bytes = GetComponent<Renderer>().material.mainTexture.EncodeToPNG();
System.IO.File.WriteAllBytes(path, bytes);
Debug.Log(bytes.Length/1024 + "Kb was saved as: " + path);
}
}
收到错误:
无法检索图像参考UnityEngine.ImageConversion:EncodeToPNG(Texture2D)
我认为您缺少一些步骤获取可用设备列表将设备名称设置为网络摄像头在设置纹理之前播放网络摄像头