【问题标题】:how to use camera in windows mobile 6 application如何在 Windows Mobile 6 应用程序中使用相机
【发布时间】:2012-09-18 21:21:45
【问题描述】:

我正在创建 windows mobile 6.5 应用程序。在该应用程序中,我必须使用图片和视频等相机操作。 有一个包含两个按钮的表单,一个用于图片,另一个用于视频。如果用户单击图片按钮,则相机启动并单击图片并将图片保存在指定位置。从应用程序捕获视频的步骤相同

任何帮助表示赞赏

提前致谢

【问题讨论】:

    标签: windows-mobile windows-mobile-6.5 windows-mobile-6


    【解决方案1】:

    查看SHCameraCapture 函数。它可以完全按照您的指定进行:使用内置的相机应用程序将视频或图像文件保存到用户定义的位置。使用此 API 制作您的应用程序只需要一些时间。

    【讨论】:

      【解决方案2】:

      最简单的方法是在Microsoft.WindowsMobile.Forms.dll上使用CameraCaptureDialog class,这种方法与硬件无关。看这个例子:

      using System.ComponentModel;
      using System.IO;
      using System.Windows.Forms;
      using Microsoft.WindowsMobile.Forms;
      
      namespace CameraExample
      {
      
          public class Form1 : Form
          {
              #region Code Designer.cs
              /// <summary>
              /// Required designer variable.
              /// </summary>
              private IContainer components;
      
              /// <summary>
              /// Clean up any resources being used.
              /// </summary>
              /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
              protected override void Dispose(bool disposing)
              {
                  if (disposing && (components != null))
                  {
                      components.Dispose();
                  }
                  base.Dispose(disposing);
              }
      
              #region Windows Form Designer generated code
      
              /// <summary>
              /// Required method for Designer support - do not modify
              /// the contents of this method with the code editor.
              /// </summary>
              private void InitializeComponent()
              {
                  this.btnPhoto = new System.Windows.Forms.Button();
                  this.btnVideo = new System.Windows.Forms.Button();
                  this.sfdFile = new System.Windows.Forms.SaveFileDialog();
                  this.SuspendLayout();
                  // 
                  // btnPhoto
                  // 
                  this.btnPhoto.Location = new System.Drawing.Point(3, 3);
                  this.btnPhoto.Name = "btnPhoto";
                  this.btnPhoto.Size = new System.Drawing.Size(72, 20);
                  this.btnPhoto.TabIndex = 0;
                  this.btnPhoto.Text = "Photo";
                  this.btnPhoto.Click += new System.EventHandler(this.btnPhoto_Click);
                  // 
                  // btnVideo
                  // 
                  this.btnVideo.Location = new System.Drawing.Point(81, 3);
                  this.btnVideo.Name = "btnVideo";
                  this.btnVideo.Size = new System.Drawing.Size(72, 20);
                  this.btnVideo.TabIndex = 1;
                  this.btnVideo.Text = "Video";
                  this.btnVideo.Click += new System.EventHandler(this.btnVideo_Click);
                  // 
                  // Form1
                  // 
                  this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
                  this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
                  this.AutoScroll = true;
                  this.ClientSize = new System.Drawing.Size(240, 294);
                  this.Controls.Add(this.btnVideo);
                  this.Controls.Add(this.btnPhoto);
                  this.MinimizeBox = false;
                  this.Name = "Form1";
                  this.Text = "Form1";
                  this.ResumeLayout(false);
      
              }
      
              #endregion
      
              private Button btnPhoto;
              private SaveFileDialog sfdFile;
              private Button btnVideo;
      
              #endregion
      
              public Form1()
              {
                  InitializeComponent();
              }
      
              enum CameraType
              {
                  Photo,
                  Video
              }
      
              private void btnPhoto_Click(object sender, System.EventArgs e)
              {
                  sfdFile.FileName = "photo.jpg";
                  sfdFile.Filter = "Image Files |*.jpg";
                  if (sfdFile.ShowDialog() == DialogResult.OK)
                      ShowCamera(sfdFile.FileName, CameraType.Photo);
              }
      
              private void btnVideo_Click(object sender, System.EventArgs e)
              {
                  sfdFile.FileName = "video.wmv";
                  sfdFile.Filter = "Video Files |*.wmv";
                  if (sfdFile.ShowDialog() == DialogResult.OK)
                      ShowCamera(sfdFile.FileName, CameraType.Video);
              }
      
              private void ShowCamera(string FileName, CameraType typeOfCamera)
              {
                  FileInfo fi = new FileInfo(FileName);
                  CameraCaptureDialog camera = new CameraCaptureDialog
                  {
                      InitialDirectory = fi.DirectoryName,
                      DefaultFileName = fi.Name,
                      Mode = typeOfCamera == CameraType.Photo ? CameraCaptureMode.Still : CameraCaptureMode.VideoWithAudio,
                      VideoTypes = CameraCaptureVideoTypes.All,
                      Title = "Using the camera"
                  };
      
                  if (camera.ShowDialog() == DialogResult.OK)
                      MessageBox.Show((typeOfCamera == CameraType.Photo ? "Photo " : "Video ") + FileName + " Captured");
                  else
                      MessageBox.Show("Not Captured");
              }
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-01-06
        • 2013-01-20
        • 2012-08-06
        相关资源
        最近更新 更多