• Unity3D调用摄像头显示当前拍摄画面


    1. using UnityEngine;  
    2. using System.Collections;  
    3.   
    4. public class CameraTest : MonoBehaviour  
    5. {  
    6.     public WebCamTexture cameraTexture;  
    7.     public string cameraName="";  
    8.     private bool isPlay = false;  
    9.     // Use this for initialization  
    10.     void Start()  
    11.     {  
    12.         StartCoroutine(Test());  
    13.     }  
    14.   
    15.     // Update is called once per frame  
    16.     void Update()  
    17.     {  
    18.   
    19.     }  
    20.   
    21.     IEnumerator Test()  
    22.     {  
    23.         yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);  
    24.         if (Application.HasUserAuthorization(UserAuthorization.WebCam))  
    25.         {  
    26.             WebCamDevice[] devices = WebCamTexture.devices;  
    27.             cameraName = devices[0].name;  
    28.             cameraTexture = new WebCamTexture(cameraName, 400, 300, 15);  
    29.             cameraTexture.Play();  
    30.             isPlay = true;  
    31.         }  
    32.     }  
    33.   
    34.     void OnGUI()  
    35.     {  
    36.         if (isPlay)  
    37.         {  
    38.             GUI.DrawTexture(new Rect(0, 0, 400, 300), cameraTexture, ScaleMode.ScaleToFit);  
    39.         }  
    40.     }  

  • 相关阅读:
    video全屏视频背景适配不同分辨率
    深入理解object.defineproperty()方法
    抓取之近似网页过滤
    基情四射的两个css样式
    Hadoop 2.4.1 登录认证配置小结
    Window中调试HBase问题小结
    改了改博客界面
    Hbase0.98.4/Hadoop2.4.1整合小结【原创】
    Hadoop 2.4.1 Map/Reduce小结【原创】
    hadoop的dfs工具类一个【原创】
  • 原文地址:https://www.cnblogs.com/yfceshi/p/6856723.html
Copyright © 2020-2023  润新知