简体   繁体   English

在用于Windows Phone 8.1的Visual Studio 13上开发简单相机应用程序时激活主相机?

[英]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 谢谢

Welcome to Stackoverflow. 欢迎使用Stackoverflow。

First I didn't get what you wrote in your code. 首先,我没有得到您在代码中编写的内容。

Here is the Sample & article for your requirement Still if you face any issue please be specify your problem. 这是您所需的示例文章 。如果仍然遇到任何问题,请指定您的问题。

Best of luck 祝你好运

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM