[英]Activate the main camera while developing a Simple Camera app on Visual Studio 13 for Windows Phone 8.1?
I am a beginner and a student who is just introduced to the WP app development, and as for my first project, I decided to build a very simple camera app, with limited functionality. 我是一个初学者,也是刚被介绍过WP应用程序开发的学生,对于我的第一个项目,我决定构建功能非常有限的非常简单的相机应用程序。 So far, I have my GUI ready, and my question is, how do I activate the main camera ( or switch between the front and the main cameras )?
到目前为止,我已经准备好GUI,我的问题是,如何激活主摄像头(或在前置和主摄像头之间切换)? This is my code on the
OnNavigatedTo
section which opens up the front camera of the phone. 这是我在
OnNavigatedTo
部分中的代码,该部分打开了手机的前置摄像头。
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
Windows.Phone.UI.Input.HardwareButtons.BackPressed += BackButtonPress;
media = new MediaCapture();
await media.InitializeAsync();
////rotation
media.SetPreviewRotation(VideoRotation.Clockwise270Degrees);
// VideoRotation previewRotation = media.GetPreviewRotation();
////start Capture preview
////capturePreview is a CaptureElement defined in XAML.
this.capPrev.Source = media;
await media.StartPreviewAsync();
}
I might be missing a simple line of code, that I am not aware of. 我可能会缺少一小段我不知道的代码。 My app right now launches the front camera instead of the main.
我的应用程序现在启动前置摄像头而不是主摄像头。 What should I do to switch to the main camera?
如何切换到主相机? (I have the switch button ready on the appbar, which currently does nothing).
(我已经在应用栏上准备了切换按钮,该按钮目前不执行任何操作)。 Thank you
谢谢
You can enumerate cameras using below given line. 您可以使用下面的给定行来枚举相机。
var set = new MediaCaptureInitializationSettings();
var devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
set.VideoDeviceId = devices[0].Id; // You should choose any value from devices collection
media = new MediaCapture();
await media.InitializeAsync(set);
Don't forget to dispose camera in OnNavigatedFrom
event. 不要忘记在
OnNavigatedFrom
事件中OnNavigatedFrom
相机。
protected async override void OnNavigatedFrom(NavigationEventArgs e)
{
await _camCapture.StopPreviewAsync();
media.Dispose();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.