📄 cecamera.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;
using System.Globalization;
using Microsoft.WindowsMobile.Forms;
using System.IO;
using ZhaoJJ2005.Forms;
namespace Cecamera
{
public partial class CECamera : Form
{
private const string cecameraDefaultInitialDirectory = null;
private const string cecameraDefaultPictureFileName = "picture1";
private const string cecameraDefaultPictureExtension = ".jpg";
private const string cecameraDefaultVideoFileName = "movie1";
private const string cecameraDefaultTitle = "Title";
private const string cecameraDefaultResolutionWidth = "100";
private const string cecameraDefaultResolutionHeight = "100";
private const string cecameraDefaultVideoTimeLimit = "25";
public CECamera()
{
InitializeComponent();
this.ResetOptions();
}
private void checkInitialDirectory_CheckStateChanged(object sender, EventArgs e)
{
this.textInitialDirectory.Enabled = this.checkInitialDirectory.Checked;
}
private void CECamera_Closed(object sender, EventArgs e)
{
Application.Exit();
}
private void checkDefaultFileName_CheckStateChanged(object sender, EventArgs e)
{
this.textDefaultFileName.Enabled = this.checkDefaultFileName.Checked;
validateFileNameInput();
}
private void checkTitle_CheckStateChanged(object sender, EventArgs e)
{
this.textTitle.Enabled = this.checkTitle.Checked;
}
private void checkResolution_CheckStateChanged(object sender, EventArgs e)
{
this.textResolutionWidth.Enabled = this.checkResolution.Checked;
this.textResolutionHeight.Enabled = this.checkResolution.Checked;
}
private void checkVideoTimeLimit_CheckStateChanged(object sender, EventArgs e)
{
this.textVideoTimeLimit.Enabled = this.checkVideoTimeLimit.Checked;
}
private void menuStart_Click(object sender, 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
{
MessageBox.Show(cameraCapture.ShowDialog().ToString());
// Displays the "Camera Capture" dialog box
if (DialogResult.OK == cameraCapture.ShowDialog())
{
string fileName = cameraCapture.FileName;
MessageBox.Show(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);
}
}
private void menuModeStill_Click(object sender, EventArgs e)
{
for (int i = 0; i < this.menuMode.MenuItems.Count; i++)
{
this.menuMode.MenuItems[i].Checked = false;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -