Android下unity3d中的webcamTexture旋转不同
我在Android设备中旋转webcamtexture时遇到困难 以下是我在编辑器中的场景: 这是我手机中的图像: 您可以看到手机和编辑器在旋转和缩放方面的差异 代码如下:Android下unity3d中的webcamTexture旋转不同,android,unity3d,webcam,Android,Unity3d,Webcam,我在Android设备中旋转webcamtexture时遇到困难 以下是我在编辑器中的场景: 这是我手机中的图像: 您可以看到手机和编辑器在旋转和缩放方面的差异 代码如下: using UnityEngine; using UnityEngine.UI; using System.Collections; public class Camera_pnl : MonoBehaviour { //// Use this for initialization WebCamTex
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class Camera_pnl : MonoBehaviour {
//// Use this for initialization
WebCamTexture webCameraTexture;
void Start() {
GUITexture BackgroundTexture = gameObject.AddComponent<GUITexture>();
BackgroundTexture.pixelInset = new Rect(0,0,Screen.width,Screen.height);
WebCamDevice[] devices = WebCamTexture.devices;
foreach (WebCamDevice cam in devices)
{
if (cam.isFrontFacing )
{
webCameraTexture = new WebCamTexture(cam.name);
webCameraTexture.deviceName = cam.name;
webCameraTexture.Play();
BackgroundTexture.texture = webCameraTexture;
}
}
}
void Update () {
if (Input.GetKey (KeyCode.Escape)) {
Invoke("LoadGame",0.1f);
}
}
void LoadGame ()
{
webCameraTexture.Stop ();
webCameraTexture = null;
Application.LoadLevelAsync("Game");
}
}
使用UnityEngine;
使用UnityEngine.UI;
使用系统集合;
公共类摄像机:单一行为{
////用于初始化
网络摄像机纹理网络摄像机纹理;
void Start(){
GuitTexture BackgroundTexture=gameObject.AddComponent();
BackgroundTexture.pixelInset=新矩形(0,0,屏幕宽度,屏幕高度);
WebCamDevice[]设备=WebCamTexture.devices;
foreach(网络摄像头设备摄像头设备)
{
如果(凸轮正对着)
{
webCameraTexture=新的WebCamTexture(cam.name);
webCameraTexture.deviceName=cam.name;
webCameraTexture.Play();
BackgroundTexture.texture=网络摄像机;
}
}
}
无效更新(){
if(Input.GetKey(KeyCode.Escape)){
调用(“加载游戏”,0.1f);
}
}
无效加载游戏()
{
webCameraTexture.Stop();
webCameraTexture=null;
Application.LoadLevelAsync(“游戏”);
}
}
如何解决此问题,使我的手机显示网络摄像头纹理的正确旋转?您需要查看旋转方向,然后旋转捕获输入的预览,这可以通过实时旋转预览来完成
int rotAngle = -webCamTexture.videoRotationAngle;
while( rotAngle < 0 ) rotAngle += 360;
while( rotAngle > 360 ) rotAngle -= 360;
在渲染webcamtexture预览时,以及在获得像素时,需要考虑这些因素。如果要保存和共享图像,则图像中的像素也必须旋转,这是在预览中逐帧执行的代价高昂的过程,这就是为什么你需要在拍完一次照片后再做
干杯读一下:
if( Application.platform == RuntimePlatform.Android ) {
flipY = !webCamTexture.videoVerticallyMirrored; }