有两种方法,常用的是GUI方法,代码如下:

public class CameraTest : MonoBehaviour {

    WebCamTexture camTexture;

    void Start () {
StartCoroutine(CallCamera());
} IEnumerator CallCamera()
{
yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);
if (Application.HasUserAuthorization(UserAuthorization.WebCam))
{
if (camTexture != null)
camTexture.Stop(); WebCamDevice[] cameraDevices = WebCamTexture.devices; string deviceName = cameraDevices[0].name;
Debug.Log(deviceName); camTexture = new WebCamTexture(deviceName);
camTexture.Play();
}
} void OnGUI()
{
if(camTexture!=null)
{
GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), camTexture, ScaleMode.StretchToFill);
}
}
}

  

GUI已经被抛弃,效率,DrawCall,适配等各种差,现使用UGUI实现:

public class CameraTest : MonoBehaviour {

    WebCamTexture camTexture;

    Image img;

    public GameObject quad;

    void Start () {
img = GetComponentInChildren<Image>();
StartCoroutine(CallCamera());
} IEnumerator CallCamera()
{
yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);
if (Application.HasUserAuthorization(UserAuthorization.WebCam))
{
if (camTexture != null)
camTexture.Stop(); WebCamDevice[] cameraDevices = WebCamTexture.devices; string deviceName = cameraDevices[0].name;
Debug.Log(deviceName); camTexture = new WebCamTexture(deviceName);
img.canvasRenderer.SetTexture(camTexture); //注意改行代码
camTexture.Play();
}
} }

  

Unity调用外部摄像头,全屏显示摄像头画面的更多相关文章

  1. QT中关于窗口全屏显示与退出全屏的实现

    近期在学习QT时遇到了很多问题这也是其中一个,个人通过在各种书籍和网络上的查阅找到了一些关于这方面的答案,希望能给大家一些帮助. 首先,在QT中对于窗口显示常用的有这么几个方法可以调用: Qt全屏显示 ...

  2. 在VC++6.0开发中实现全屏显示

    全屏显示是一些应用软件程序必不可少的功能.比如在用VC++编辑工程源文件或编辑对话框等资源时,选择菜单“View\Full Screen”,即可进入全屏显示状态,按“Esc”键后会退出全屏显示状态. ...

  3. 启动app时全屏显示Default.png

    一直很喜欢MJ的讲课视频,今天看了他的博客学到了些东西顺便记录下来. 在默认情况下,app显示Default.png时并非真正的"全屏显示",因为顶部的状态栏并没有被隐藏,比如下面 ...

  4. C# WinForm中 让控件全屏显示的实现代码

    夏荣全 ( lyout(at)163.com )原文 C#中让控件全屏显示的实现代码(WinForm) 有时候需要让窗口中某一块的内容全屏显示,比如视频播放.地图等等.经过摸索,暂时发现两种可行方法, ...

  5. Qt on Android:让 Qt Widgets 和 Qt Quick 应用全屏显示

    Android 系统版本号非常多,较新的 4.4 ,较老的 2.3 ,都有人用. Qt on Android 开发的 Android 应用.默认在 Android 设备上是非全屏的. 而有些应用的需求 ...

  6. 全屏显示网页FULLSCREEN API

    第一次看到应用 Fullscreen API 全屏显示网页,是 FaceBook 中的照片放大.作为一个比较新的 API,目前只有 Safari.Chrome 和 FireFox 三种浏览器支持该特性 ...

  7. Qt全屏显示窗口、子窗口的相关函数

    Qt全屏显示函数         window.showFullScreen() Qt最大化显示函数         window.showMaximized() Qt最小化显示函数         ...

  8. JavaScript:让浏览器全屏显示

    并不是所有人都会按F11让浏览器全屏显示~~~ 一.直接上代码 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xh ...

  9. Android 全屏显示的方法(不包含状态栏)

    我们都知道在Android中某些功能的实现往往有两种方法:一种是在xml文件中设置相应属性,另一种是用代码实现.同样Android实现全屏显示也可以通过这两种方法实现: 1.在AndroidManif ...

随机推荐

  1. p4171&bzoj1823 满汉全席

    传送门(洛谷) 传送门(bzoj) 题目 满汉全席是中国最丰盛的宴客菜肴,有许多种不同的材料透过满族或是汉族的料理方式,呈现在數量繁多的菜色之中.由于菜色众多而繁杂,只有极少數博学多闻技艺高超的厨师能 ...

  2. 11、scala类型参数

    一.类型参数1 1.介绍 类型参数是什么?类型参数其实就类似于Java中的泛型.先说说Java中的泛型是什么,比如我们有List a = new ArrayList(),接着a.add(1),没问题, ...

  3. 在Visual Studio开发的项目中引用GAC中的dll

    Open the windows Run dialog (Windows Key + r) Type C:\Windows\assembly\gac_msil. This is some sort o ...

  4. C# 写 LeetCode easy #26 Remove Duplicates from Sorted Array

    26.Remove Duplicates from Sorted Array Given a sorted array nums, remove the duplicates in-place suc ...

  5. Codeforces Round #523 (Div. 2)C(DP,数学)

    #include<bits/stdc++.h>using namespace std;long long a[100007];long long dp[1000007];const int ...

  6. HTML基本标签问题总结

    一.常见的内联元素和块元素 块级元素: div, form, (列表相关ul,dl,ol,li,) h1-6,p,table 内联元素: a, br, u,(b , em, strong, i,) i ...

  7. 牛客网NOIP赛前集训营-提高组(第四场)B题 区间

    牛客网NOIP赛前集训营-提高组(第四场) 题目描述 给出一个序列 a1, ..., an. 定义一个区间 [l,r] 是好的,当且仅当这个区间中存在一个 i,使得 ai 恰好等于 al, al+1, ...

  8. LaTeX使用心得

    LaTeX是一个功能强大的,开源的排版工具. 最近教练让我们做课件,我做数论,鉴于LaTeX的数学公式功能强大(而MS办公软件的数学公式简直就是个LJ)和我的学习精神,我决定用LaTeX写课件. 在一 ...

  9. PHPExcel探索之旅---阶段四 导入文件

    步骤就是:实例化excel读取对象=> 加载excel文件 => 读取excel文件(全部读取.逐行读取) <?php header("Content Type :text ...

  10. 使用nsenter工具进入Docker容器

    查看本机装没有nsenter whereis nsenter或者whatis nsenter 未安装先安装,网上有很多这样的脚本 vi nsenter.sh #!/bin/bashcurl https ...