积极答复者
mobile 5.0读取pda摄像头数据

问题
答案
-
调用CameraCaptureDialog类。
示例:
private void menuStart_Click(object sender, System.EventArgs e)
{
CameraCaptureDialog cameraCapture = new CameraCaptureDialog();
cameraCapture.Owner = this;// Specify the options as user specified.
if (this.checkInitialDirectory.Checked)
{
cameraCapture.InitialDirectory = this.textInitialDirectory.Text;
}
if (this.checkDefaultFileName.Checked)
{
if (this.menuModeStill.Checked)
{
if (cameraCapture.DefaultFileName != null)
{
// It is necessary to end picture files with ".jpg".
// Otherwise the argument is invalid.
cameraCapture.DefaultFileName = cameraCapture.DefaultFileName + cecameraDefaultPictureExtension;
}
}
else
{
// If it is a video, pass null. This will return a filename with a
// correct extension. Later on we rename the file and keep the extension.
cameraCapture.DefaultFileName = null;
}
}if (this.checkTitle.Checked)
{
cameraCapture.Title = this.textTitle.Text;
}
if (this.checkResolution.Checked)
{
int resolutionWidth = 0;
int resolutionHeight = 0;if (!ConvertStringToInt(this.textResolutionWidth.Text, ref resolutionWidth))
{
MessageBox.Show("Please input a valid resolution width.", this.Text,
MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
textResolutionWidth.Focus();
return;
}
if (!ConvertStringToInt(this.textResolutionHeight.Text, ref resolutionHeight))
{
MessageBox.Show("Please input a valid resolution height.", this.Text,
MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
textResolutionHeight.Focus();
return;
}cameraCapture.Resolution = new Size(resolutionWidth, resolutionHeight);
}
if (this.checkVideoTimeLimit.Checked)
{
int videoTimeLimit = 0;if (!ConvertStringToInt(this.textVideoTimeLimit.Text, ref videoTimeLimit))
{
MessageBox.Show("Please input a valid video time limit.", this.Text,
MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
textVideoTimeLimit.Focus();
return;
}cameraCapture.VideoTimeLimit = new TimeSpan(0, 0, videoTimeLimit);
}// Specify capture mode
if (this.menuModeStill.Checked)
{
cameraCapture.Mode = CameraCaptureMode.Still;
}
else if (this.menuModeVideoOnly.Checked)
{
cameraCapture.Mode = CameraCaptureMode.VideoOnly;
}
else if (this.menuModeVideoWithAudio.Checked)
{
cameraCapture.Mode = CameraCaptureMode.VideoWithAudio;
}// Specify still quality
if (this.menuStillQualityDefault.Checked)
{
cameraCapture.StillQuality = CameraCaptureStillQuality.Default;
}
else if (this.menuStillQualityLow.Checked)
{
cameraCapture.StillQuality = CameraCaptureStillQuality.Low;
}
else if (this.menuStillQualityNormal.Checked)
{
cameraCapture.StillQuality = CameraCaptureStillQuality.Normal;
}
else if (this.menuStillQualityHigh.Checked)
{
cameraCapture.StillQuality = CameraCaptureStillQuality.High;
}// Specify video types
if (this.menuVideoTypesAll.Checked)
{
cameraCapture.VideoTypes = CameraCaptureVideoTypes.All;
}
else if (this.menuVideoTypesStandard.Checked)
{
cameraCapture.VideoTypes = CameraCaptureVideoTypes.Standard;
}
else if (this.menuVideoTypesMessaging.Checked)
{
cameraCapture.VideoTypes = CameraCaptureVideoTypes.Messaging;
}try
{
// Displays the "Camera Capture" dialog box
if (DialogResult.OK == cameraCapture.ShowDialog())
{
string fileName = cameraCapture.FileName;// If it is a video we rename the file so that it has the user entered
// default filename and the correct extension.
if (cameraCapture.Mode != CameraCaptureMode.Still)
{
string extension = fileName.Substring(fileName.LastIndexOf("."));
string directory = "";if (fileName.LastIndexOf("\\") != -1)
{
directory = fileName.Substring(0, fileName.LastIndexOf("\\") + 1);
}fileName = directory + this.textDefaultFileName.Text + extension;
System.IO.File.Move(cameraCapture.FileName, fileName);
}// The method completed successfully.
MessageBox.Show("The picture or video has been successfully captured and saved to:\n\n" + fileName,
this.Text, MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
}
}
catch (ArgumentException ex)
{
// An invalid argument was specified.
MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK,
MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
}
catch (OutOfMemoryException ex)
{
// There is not enough memory to save the image or video.
MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK,
MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
}
catch (InvalidOperationException ex)
{
// An unknown error occurred.
MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK,
MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
}
}基本上就是对该类的操作。详见...\Windows Mobile 5.0 SDK R2\Samples\PocketPC\Cs\Cecamera
- 已标记为答案 微软中文技术论坛Moderator 2009年6月15日 5:45