参考链接:http://www.cnblogs.com/Erma-king/p/5869177.html

不过该博主是竖屏,我的是横屏

代码修改:

using UnityEngine;
using System.Collections;
using UnityEngine.UI;
/// <summary>
/// 调用摄像机并自适应大小的脚本
/// </summary>
public class STCamDeviceController : MonoBehaviour
{ WebCamTexture camTexture;
CanvasScaler CanScaler;
Camera ca;
Image img; void Start()
{ img = GetComponentInChildren<Image>(); CanScaler = GetComponentInChildren<CanvasScaler>();
CanScaler.referenceResolution = new Vector2(Screen.width, Screen.height); ca = GetComponentInChildren<Camera>();
ca.orthographicSize = Screen.width / 100.0f / 2.0f; //img.transform.localScale = new Vector3(-1, -1, -1); img.rectTransform.anchorMin = new Vector2(0.5f, 0.5f);
img.rectTransform.anchorMax = new Vector2(0.5f, 0.5f);
img.rectTransform.pivot = new Vector2(0.5f, 0.5f); img.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, Screen.width);
img.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, Screen.height); // 设备不同的坐标转换
#if UNITY_IOS || UNITY_IPHONE
img.transform.Rotate (new Vector3 (, , ));
#elif UNITY_ANDROID
img.transform.Rotate (new Vector3 (, , ));
#endif 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[].name; camTexture = new WebCamTexture(deviceName, Screen.height, Screen.width, );
img.canvasRenderer.SetTexture(camTexture); camTexture.Play();
}
}
}

调用摄像头并将其显示在UGUI image上自适应屏幕大小的更多相关文章

  1. unity调用摄像头的方法

    http://blog.csdn.net/cocoa_china/article/details/10527995 using UnityEngine; using System.Collection ...

  2. Android入门(十六)调用摄像头相册

    原文链接:http://www.orlion.ga/665/ 一.调用摄像头 创建一个项目ChoosePicDemo,修改activity_main.xml: <LinearLayout xml ...

  3. matlab2015b调用摄像头

    参考链接:http://blog.csdn.net/lyqmath/article/details/7307429 本人电脑是宏碁T5000 调用代码: % By lyqmathclc; clear ...

  4. [Unity3D]unity3d5.0简单的调用摄像头

    Unity3D中新建一个工程,加一个Plane,新建一个C# 脚本,将这个脚本添加到Plane上,调用摄像头.(如果显示的图片居然是翻转的,Plane的Rotation 值就可以了) 以下是脚本内容: ...

  5. 【MediaKit】WPF项目中 调用摄像头拍照的开发包

    今天遇到一个 人事的项目,项目中需要调用摄像头给员工照相.如何解决这个问题呢? 介绍一个开发包给你,MediaKit.论坛里头的人都说好,但是黑兔觉得大家好才是真的好.你不妨试试~ 第一步:添加WPF ...

  6. Android开发中如何调用摄像头的功能

    我们要调用摄像头的拍照功能,显然 第一步必须加入调用摄像头硬件的权限,拍完照后我们要将图片保存在SD卡中,必须加入SD卡读写权限,所以第一步,我们应该在Android清单文件中加入以下代码     & ...

  7. python+opencv读取视频,调用摄像头

    引用 import cv2 import numpy 创建摄像头对象 cap = cv2.VideoCapture("videoTest/test1.mp4") #参数为视频文件目 ...

  8. JAVA中通过JavaCV实现跨平台视频/图像处理-调用摄像头

    一.简介 JavaCV使用来自计算机视觉领域(OpenCV, FFmpeg, libdc1394, PGR FlyCapture, OpenKinect, librealsense, CL PS3 E ...

  9. 【C#】#100 调用摄像头

    需求:由于项目需要获得用户的头像,所以需要用C#调用摄像头获取头像. 下面写一个调用摄像头的方法 案例:调用摄像头的一个DEMO[效果图] 使用的类库:AForge.dll   [Demo下载,Dem ...

随机推荐

  1. You can add an index on a column that can have NULL values if you are using the MyISAM, InnoDB, or MEMORY storage engine.

    w https://dev.mysql.com/doc/refman/5.7/en/create-index.html MySQL :: MySQL 5.7 Reference Manual :: B ...

  2. Extract, Transform, Load

    w https://en.wikipedia.org/wiki/Extract,_transform,_load

  3. Linux学习拾遗

    一.安装iso文件 首先建立一个目录作为挂载点:# mkdir /mnt/iso 获得root权限然后使用下面的参数挂载ISO映像文件:# mount -t iso9660 /path/image.i ...

  4. 【题解】Journeys(线段树优化连边)

    [#3073. Pa2011]Journeys (线段树优化连边) 这张图太直观了,直接讲透了线段树优化连边的原理和正确性. 考虑建立两颗线段树,一颗是外向树,一颗是内向树,相当于网络流建模一样,我们 ...

  5. 字符串之strchr

    功能:查找字符在字符串中第一次出现的位置. #include <iostream> #include <assert.h> using namespace std; char ...

  6. LeetCode:下一个排列【31】

    LeetCode:下一个排列[31] 题目描述 实现获取下一个排列的函数,算法需要将给定数字序列重新排列成字典序中下一个更大的排列. 如果不存在下一个更大的排列,则将数字重新排列成最小的排列(即升序排 ...

  7. PHP 实现Session入库/存入redis

    对于大访问量的站点使用默认的Session 并不合适,我们可以将其存入数据库.或者使用Redis KEY-VALUE数据存储方案 首先新建一个session表 CREATE TABLE `sessio ...

  8. Loadrunder之脚本篇——关联函数对话框详解

    Insert->New Step,打开Add Step对话框 选择函数web_reg_save_param,点击OK,打开关联函数设置窗口 说明: Parameter Name 此处设置存放参数 ...

  9. OpenGL学习进程(9)在3D空间的绘制实例

        本节将演示在3D空间中绘制图形的几个简单实例:     (1)在3D空间内绘制圆锥体: #include <GL/glut.h> #include <math.h> # ...

  10. 【HackerRank】Missing Numbers

    Numeros, The Artist, had two lists A and B, such that, B was a permutation of A. Numeros was very pr ...