您的位置:首页 > 其它

mobile调用手机摄像机程序

2010-03-22 17:05 316 查看
想实现通过程序调用手机的拍照摄像功能,原打算调用api不过去这方面不懂,查了好长时间终于凑成了一个简的小程序,贴出来:
代码

using System;
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.IO;

namespace video22
{
public partial class Form1 : Form
{
//摄像窗体
private CameraCaptureDialog cameraCapture = new CameraCaptureDialog();
//保存路径
private string path = @"\My Documents\测试";
//文件名
private string filname = "";
public Form1()
{
InitializeComponent();
cameraCapture.Owner = this;
}
/// <summary>
/// 短视频50秒
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuItem4_Click(object sender, EventArgs e)
{

cameraCapture.Mode = CameraCaptureMode.VideoOnly;
//摄像时限50秒
cameraCapture.VideoTimeLimit = new TimeSpan(0, 0, 50);
}
/// <summary>
/// 文件保存
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuItem2_Click(object sender, EventArgs e)
{
if (cameraCapture.ShowDialog() == DialogResult.OK)//如果拍摄后按下确定按钮
{
try
{
//随机文件名
string str1 = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString();
//获取扩展名
string str = cameraCapture.FileName.Substring(cameraCapture.FileName.IndexOf("."));
filname = path + @"\" + str1 + str;
//将文件保存到指定路径
File.Move(cameraCapture.FileName,filname);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
MessageBox.Show("文件已经成功保存!");
}
}

/// <summary>
/// 拍照功能
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuItem3_Click(object sender, EventArgs e)
{
cameraCapture.Mode = CameraCaptureMode.Still;
}
/// <summary>
/// 长视频13分钟
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuItem5_Click(object sender, EventArgs e)
{
cameraCapture.Mode = CameraCaptureMode.VideoWithAudio;
}

//private void menuItem6_Click(object sender, EventArgs e)
//{
// if (filname != "")
// {
// SelectPictureDialog ch = new SelectPictureDialog();
// ch.ShowDialog();
// }
//}

private void menuItem7_Click(object sender, EventArgs e)
{
//if (filname != "")
//{
// try
// {
// StreamWriter sr0 = new StreamWriter(@"\My Documents\测试2" + filname.Substring(filname.LastIndexOf("\\")));
// Stream sr1 = File.OpenRead(filname);
// byte[] bs = new byte[sr1.Length];
// sr1.Read(bs, 0, (int)sr1.Length);
// sr0.Write(bs);
// }
// catch (Exception)
// {
// throw;
// }
//}
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐