Sor*_*ora 8 webcam android unity-game-engine
我在Android设备中旋转webcamtexture时遇到了困难.
这是我在编辑器中的场景:

这是手机中的图像:

您可以看到手机和编辑器之间的旋转和缩放差异.
这是代码:
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");
}
}
Run Code Online (Sandbox Code Playgroud)
如何解决此问题,以便我的手机显示正确的webcamtexture旋转?
您需要查看旋转方向,然后旋转捕获的输入的预览,这可以通过实时旋转预览来完成。
int rotAngle = -webCamTexture.videoRotationAngle;
while( rotAngle < 0 ) rotAngle += 360;
while( rotAngle > 360 ) rotAngle -= 360;
Run Code Online (Sandbox Code Playgroud)
以下代码来自相机捕获套件,我们使用它的插件(https://www.assetstore.unity3d.com/en/#!/content/56673) - 我们将其用于社交游戏/应用程序,让用户可以拍摄并分享游戏内的照片。
在某些情况下,当旋转为 270 度或 90 度时,您还需要翻转图像。这是 Android 的代码。
if( Application.platform == RuntimePlatform.Android ) {
flipY = !webCamTexture.videoVerticallyMirrored; }
Run Code Online (Sandbox Code Playgroud)
当你渲染网络摄像头纹理的预览以及获取像素时,你需要考虑这些因素,如果你想保存和共享图像,图像中的像素也必须旋转,即在预览中逐帧进行预览的过程成本高昂,这就是为什么您需要在照片拍摄一次后进行此操作。
干杯
| 归档时间: |
|
| 查看次数: |
3693 次 |
| 最近记录: |