mobile调用手机摄像机程序

想实现通过程序调用手机的拍照摄像功能,原打算调用api不过去这方面不懂,查了好长时间终于凑成了一个简的小程序,贴出来:
ExpandedBlockStart.gif 代码
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;
            
//     }
            
// }
        }
    }
}

 

转载于:https://www.cnblogs.com/gjs85/archive/2010/03/22/1691745.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值