代码之家  ›  专栏  ›  技术社区  ›  ytoledano

在Windows Phone 7中显示摄像头输出

  •  3
  • ytoledano  · 技术社区  · 15 年前

    我正在为WindowsPhone7编写一个增强现实应用程序作为学校项目。我想得到相机的输出,然后在上面添加一层数据。有没有办法让摄像头输出显示在面板上?

    5 回复  |  直到 15 年前
        1
  •  7
  •   mattStroshane    15 年前

    仅供参考:在WindowsPhoneSDK7.1(又名“Mango”)中,您现在可以编写使用设备摄像头的应用程序。见 App Hub

    How to: Create a Base Camera Application for Windows Phone

    但基本上,添加一个视频画笔来显示相机的输入(也就是“取景器”)。例如,此处使用矩形控件显示相机取景器:

        <!--Camera viewfinder >-->
        <Rectangle Width="640" Height="480" 
                   HorizontalAlignment="Left" 
                   x:Name="viewfinderContainer">
    
            <Rectangle.Fill>
                <VideoBrush x:Name="viewfinderBrush" />
            </Rectangle.Fill>
        </Rectangle>
    

    若要在页面的代码隐藏中使用相机,请添加对Microsoft.XNA.Framework的引用,并在页面顶部放置以下Using语句:

    // Directives
    using Microsoft.Devices;
    using System.IO;
    using System.IO.IsolatedStorage;
    using System.Windows.Media.Imaging;
    using Microsoft.Xna.Framework.Media;
    

    注意:您可能不需要所有这些,我只是从文档中复制过来的。在Visual Studio(至少是Pro)中,右键单击代码文件并单击: 组织使用 | 删除未使用的using

    然后,基本上将相机图像应用到 处理程序。。。

        //Code for initialization and setting the source for the viewfinder
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
    
            // Initialize camera
            cam = new Microsoft.Devices.PhotoCamera();
    
            //Set the VideoBrush source to the camera.
            viewfinderBrush.SetSource(cam);
        }
    

    从导航 .

        protected override void OnNavigatingFrom(System.Windows.Navigation.NavigatingCancelEventArgs e)
        {
            // Dispose camera to minimize power consumption and to expedite shutdown.
            cam.Dispose();
    
            // Good place to unhook camera event handlers too.
        }
    

    创建基于Silverlight的增强现实应用程序 ,找到用芒果建造它的说明。

    How to: Use the Combined Motion API for Windows Phone

    希望这也有助于其他人在WindowsPhoneOS7.1中寻找有关光摄像头的信息。

    干杯

        2
  •  4
  •   Austyn Mahoney Janak    15 年前

    根据微软的 UI Design and Interaction Guide [PDF],它们不允许开发人员使用任何UI元素访问相机。

    没有直接的UI元素 开发人员可以使用摄像机 在Microsoft.Phone.Tasks中 命名空间。

        3
  •  1
  •   Greg Bray    15 年前

    从今天(2010年1月19日)起,您只能正式访问使用CameraCaptureTask拍摄的照片。如果您不打算向市场提交申请,那么您可以使用 Microsoft.Phone.Media.Extended this post 视频演示和 his blog 更多细节。请注意,如果使用这些程序集,则应用程序将不会通过市场认证,因为它们不是官方SDK的一部分。

        4
  •  0
  •   Ed Altorfer    15 年前

    你问题的简短回答是:不。

    您可以使用 CameraCaptureTask 由Windows Phone 7 API提供( here )但是,据我所知,你无法从摄像机中捕捉到实时数据流。

    微软还没有宣布这个功能是否会在该平台的未来版本中得到增强。

    使用示例 照相机捕获任务 :

    public partial class MainPage : PhoneApplicationPage
    {
       // Declare the CameraCaptureTask object with page scope.
       CameraCaptureTask cameraCaptureTask;
    
       // Constructor
       public MainPage()
       {
          InitializeComponent();
    
          // Initialize the CameraCaptureTask and assign the Completed handler in the page constructor.
          cameraCaptureTask = new CameraCaptureTask();
          cameraCaptureTask.Completed += new EventHandler<PhotoResult>(cameraCaptureTask_Completed);
       }
    
       // In this example, the CameraCaptureTask is shown in response to a button click.                
       private void button1_Click(object sender, RoutedEventArgs e)
       {
          cameraCaptureTask.Show();
       }
       // The Completed event handler. In this example, a new BitmapImage is created and
       // the source is set to the result stream from the CameraCaptureTask
       void cameraCaptureTask_Completed(object sender, PhotoResult e)
       {
          if (e.TaskResult == TaskResult.OK)
          {
             BitmapImage bmp = new BitmapImage();
             bmp.SetSource(e.ChosenPhoto);
             myImage.Source = bmp;
          }
       }
    }
    
        5
  •  0
  •   Mick N    15 年前

    最近发布的信息表明支持AR的功能已经在路线图上。

    推荐文章