c# - 在 Hololens 中运行时未调用 OnPhotoCaptureCreated
问题描述
我正在尝试制作一个可以在 Hololens 中拍摄照片的应用程序。我已按照教程进行操作,几乎复制了教程代码。当我在 Unity 的计算机上运行它时,它可以工作并使用我的网络摄像头拍照。但是当我在 Hololens 上运行它时它不起作用。我有问题的代码部分在这里:
void Start() {
startHeadPosition = Camera.main.transform.position;
newHeadPosition = startHeadPosition;
dIndikator.text = "";
CreateScene("Test");
Debug.Log("\n Taking picture \n");
PhotoCapture.CreateAsync(false, OnPhotoCaptureCreated);
Debug.Log("\n Debug 2 \n");
}
void OnPhotoCaptureCreated(PhotoCapture captureObject)
{
Debug.Log("\n Debug 1 \n");
photoCaptureObject = captureObject;
m_cameraResolution = PhotoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).Last();
CameraParameters c = new CameraParameters();
c.hologramOpacity = 0.0f;
c.cameraResolutionWidth = m_cameraResolution.width;
c.cameraResolutionHeight = m_cameraResolution.height;
c.pixelFormat = CapturePixelFormat.JPEG;
Debug.Log("\n PhotoModeStarted \n");
captureObject.StartPhotoModeAsync(c, OnPhotoModeStarted);
}
在 Unity 中,日志如下所示:
拍照
调试 2
调试 1
照片模式已启动
但是在 Hololens 中,我只得到:
拍照
调试 2
所以看起来它甚至没有进入 OnPhotoCaptureCreated。我已经为相机和麦克风设置了功能,并确保我在清单文件中有它们,所以我不知道是什么导致了这个问题。我还确保在 Hololens 隐私设置中为该应用启用了摄像头。
任何想法都非常感谢。
解决方案
通常,不会执行回调方法,PhotoCapture.CreateAsync
因为您的应用程序没有使用相机的权限。
转到Settings/Privacy/Camera/
并启用"Let apps use my camera"
推荐阅读
- asp.net - 使用 MS Access 数据库发布 asp.net
- javascript - 通过 mocha.run() 运行测试时,如何将 es6 模块与 mocha 一起使用?
- drupal - Drupal CKEditor 自定义样式
- django - Django - 如何查询相关的翻译模型?
- java - Spring Data JPA 按属性排序,无需硬编码
- python - 如何使用 Python - Bot 在 Telegram 频道上捕获引荐来源网址 - 组?
- python - random.randint() 生成一致的模式
- android - 如何从 Map 获取数组值
> 并放入 setOnMarkerClickListener? - java - 在android中杀死应用程序后执行代码
- kubernetes - Kubernetes Pod 数量与 CPU 请求数量