以下为Windows CE平台下对PDA等移动终端设备摄像头进行操作的实例,可以实对摄像头的调用,拍照或者录制视频后自动保存到制定路径。
using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.WindowsMobile.Forms;
using System.Diagnostics;
namespace PhotoCapture
{
public partial class frmPC : Form
{
private clsCamera clsCamera = new clsCamera();
public frmPC()
{
InitializeComponent();
}
private void frmPC_Closed(object sender, EventArgs e)
{
Application.Exit();
}
private void menuVedio_Click(object sender, EventArgs e)
{
try
{
CameraCaptureDialog cameraCapture = new CameraCaptureDialog();
cameraCapture.Owner = null;
cameraCapture.InitialDirectory = @"\My Documents";
cameraCapture.DefaultFileName = @"PDA_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".3gp";
cameraCapture.Title = "Camera Demo";
cameraCapture.VideoTypes = CameraCaptureVideoTypes.Messaging;
cameraCapture.Resolution = new Size(176, 144);
cameraCapture.VideoTimeLimit = new TimeSpan(0, 0, 15);
//cameraCapture.VideoTimeLimit = new TimeSpan(0, 0, 10); // Limited to 15 seconds of video.
cameraCapture.Mode = CameraCaptureMode.VideoWithAudio;
if (DialogResult.OK == cameraCapture.ShowDialog())
{
this.Refresh();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void menuPhoto_Click(object sender, EventArgs e)
{
try
{
CameraCaptureDialog cameraCapture = new CameraCaptureDialog();
cameraCapture.Owner = null;
cameraCapture.InitialDirectory = @"\My Documents";
cameraCapture.DefaultFileName = @"PDA_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".jpg";
cameraCapture.Title = "Take the picture";
cameraCapture.Resolution = new Size(800, 600);
cameraCapture.Mode = CameraCaptureMode.Still;
cameraCapture.StillQuality = CameraCaptureStillQuality.High;
if (DialogResult.OK == cameraCapture.ShowDialog())
{
this.Refresh();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}