参考链接: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. Asp.Net MVC anti-forgery token的问题:nameidentifier not present

    前一篇关于anti-forgery token问题的博文提到我们可以通过修改AntiForgeryConfig.UniqueClaimTypeIdentifier属性来避免AntiForgeryTok ...

  2. Js用户引导插件bootstrap-tour

    1.demo直接贴上来了,有什么不懂的,直接去官网上看,地址:http://bootstraptour.com/. 2.这个bootstrap-tour插件的版本是v0.12.0,复制下来代码,引入库 ...

  3. spring下配置shiro

    1.web.xml中加入shiro的过滤器: <!-- Spring --> <!-- 配置Spring配置文件路径 --> <context-param> < ...

  4. spring tiles界面为空白

    Caused by: org.apache.jasper.JasperException: /WEB-INF/views/admin_template.jsp(3,62) Unable to read ...

  5. linux环回文件

    我们通常在设备上(比如磁盘分区)上创建文件系统,这些存储设备能够以设备文件的形式来使用,如/dev/device_name.为了使用存储设备上的文件系统,我们将其挂载到挂载点. 环回文件系统是指那些在 ...

  6. PyQt4 颜色选择,字体选择代码

    # -*- coding: utf-8 -*- """ ------------------------------------------------- File Na ...

  7. Objective-C 继承和多态

    学习Java我们知道类有三大特征,封装,继承,多态.而在Objective-C中也有继承的概念,今天就来看看Objective-C中的继承和多态. 首先,我们来看看示例代码: //Animal.h # ...

  8. Ubuntu安装配置samba

    一. samba的安装: sudo apt-get insall sambasudo apt-get install smbfs 二. 创建共享目录: mkdir /home/chars/shares ...

  9. Ubuntu 下 java 版本的切换

    切换的方法很简单,使用下面的两个命令即可: update-alternatives --config java update-alternatives --config javac eg: root@ ...

  10. Web Deploy 安装及问题解决

    注意: 站点名称:  服务器上IIS的站点名称.  . 我之前这里随便写一直不成功. 返回500..... 用户名, 密码:  这里最好用windows帐号. 问题比较少. 目标URL: 可不写. 可 ...