gpt4 book ai didi

android - Android 下 unity3d 中的 webcamTexture 旋转不同

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:00:04 28 4
gpt4 key购买 nike

我在我的 Android 设备中旋转网络摄像头纹理时遇到困难。

这是我在编辑器中的场景: enter image description here

这是我手机里的图片: enter image description here

您可以看到手机和编辑器在旋转和缩放方面的差异。

代码如下:

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");
}
}

如何解决此问题,以便我的手机显示正确的网络摄像头纹理旋转?

最佳答案

您需要查看旋转方向,然后旋转捕获输入的预览,这可以通过实时旋转预览来完成。

int rotAngle = -webCamTexture.videoRotationAngle;
while( rotAngle < 0 ) rotAngle += 360;
while( rotAngle > 360 ) rotAngle -= 360;

以下代码来 self 们用于 ( https://www.assetstore.unity3d.com/en/#!/content/56673 ) 的 Camera Capture Kit 插件 - 我们将其用于社交游戏/应用,让用户在游戏中拍摄和分享照片。

在某些情况下,当旋转为 270 度或 90 度时,您也需要翻转图像。这是 Android 的代码。

if( Application.platform == RuntimePlatform.Android ) {
flipY = !webCamTexture.videoVerticallyMirrored; }

在渲染网络摄像头纹理的预览时以及获取像素时需要考虑这些因素,如果要保存和共享图像,图像中的像素也必须旋转,这是一个在预览中逐帧进行的昂贵过程,这就是为什么您需要在拍摄一次照片后进行此操作的原因。

干杯

关于android - Android 下 unity3d 中的 webcamTexture 旋转不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28927223/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com