C# Units PhotoCapture的SupportedResolutions为空
我正在使用Unity为全息透镜编程一个应用程序。在应用程序中,我需要一个按钮,它在单击时记录图像。为了拍照,我尝试使用Unitys PhotoCapture(如此处所述:或此处所述:)。 当我运行代码并单击按钮时,出现以下错误:C# Units PhotoCapture的SupportedResolutions为空,c#,unity3d,hololens,C#,Unity3d,Hololens,我正在使用Unity为全息透镜编程一个应用程序。在应用程序中,我需要一个按钮,它在单击时记录图像。为了拍照,我尝试使用Unitys PhotoCapture(如此处所述:或此处所述:)。 当我运行代码并单击按钮时,出现以下错误:System.invalidoOperationException:“序列不包含元素”关于以下行:cameraResolution=PhotoCapture.SupportedResolutions.OrderByDescending((res)=>res.width*r
System.invalidoOperationException:“序列不包含元素”
关于以下行:cameraResolution=PhotoCapture.SupportedResolutions.OrderByDescending((res)=>res.width*res.height).First()
通过调试,我发现SupportedResolutions
是空的。我怎样才能解决这个问题
代码的其余部分:
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.XR.WSA.WebCam;
using UnityEngine.XR.WSA.Input;
using HoloToolkit.Unity.InputModule;
public class Record : MonoBehaviour, IInputClickHandler {
PhotoCapture photoCaptureObject = null;
Resolution cameraResolution;
void Start () {}
public void OnInputClicked(InputClickedEventData eventData)
{
cameraResolution = PhotoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).First();
// Create a PhotoCapture object and so on
}
(麦克风和网络摄像头在Unity中作为输入启用)在尝试访问其分辨率之前,需要实例化photoCaptureObject 在尝试访问其分辨率之前,需要实例化photoCaptureObject 正如您所说,在填充PhotoCapture之前,需要调用
PhotoCapture.CreateAsync
您可以在下面获得代码示例和代码片段:
private void Start()
{
PhotoCapture.CreateAsync(false, this.OnPhotoCreated);
}
// This method store the PhotoCapture object just created and retrieve the high quality
// available for the camera and then request to start capturing the photo with the
// given camera parameters.
private void OnPhotoCreated(PhotoCapture captureObject)
{
Resolution cameraResolution = PhotoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).First();
CameraParameters c = new CameraParameters()
{
hologramOpacity = 0.0f,
cameraResolutionWidth = cameraResolution.width,
cameraResolutionHeight = cameraResolution.height,
pixelFormat = CapturePixelFormat.BGRA32
};
// captureObject.StartPhotoModeAsync(c, this.OnPhotoModeStarted);
}
正如您所说,在填充PhotoCapture之前,需要调用
PhotoCapture.CreateAsync
您可以在下面获得代码示例和代码片段:
private void Start()
{
PhotoCapture.CreateAsync(false, this.OnPhotoCreated);
}
// This method store the PhotoCapture object just created and retrieve the high quality
// available for the camera and then request to start capturing the photo with the
// given camera parameters.
private void OnPhotoCreated(PhotoCapture captureObject)
{
Resolution cameraResolution = PhotoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).First();
CameraParameters c = new CameraParameters()
{
hologramOpacity = 0.0f,
cameraResolutionWidth = cameraResolution.width,
cameraResolutionHeight = cameraResolution.height,
pixelFormat = CapturePixelFormat.BGRA32
};
// captureObject.StartPhotoModeAsync(c, this.OnPhotoModeStarted);
}