CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
IBM Rational 系统开发最佳实践工具包 WebSphere MQ 最佳实践 TOP 15
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  .NET技术 >  C#

有人作过摄像头的程序没有,在预览的同时录像为什么界面象死机?

楼主cq_lqj(程序员秘书)2006-03-13 10:20:54 在 .NET技术 / C# 提问

开始运行程序时设置好预览,这时我开始录像,鼠标就变成“酒杯状”,但预览在正常进行,录像也正常进行,停止通过按ESC键,该程序失去焦点后也停止。我本想作过停止按钮都不好作了。  
   
   
  有哪位知道或遇到过同样的问题,请指点指点,谢谢了! 问题点数:50、回复次数:9Top

1 楼luqinjian(大海)回复于 2006-03-13 11:42:55 得分 10

关注Top

2 楼zlz_212(ShREk)回复于 2006-03-13 11:55:58 得分 10

关注Top

3 楼wxdl1981(沉默之狼)回复于 2006-03-13 12:10:15 得分 10

是不是因为录象时占用CPU资源太多引起的.  
  你用多线程试试Top

4 楼cq_lqj(程序员秘书)回复于 2006-03-13 12:21:25 得分 0

单独录像开一个线程,是可以的  
  预览同时录像,开多线程也是一样的现象Top

5 楼blackhero(黑侠客)回复于 2006-03-13 15:26:08 得分 10

你做的是cs   or   bs的呀Top

6 楼luckin(aliang)回复于 2006-04-27 16:35:34 得分 10

using   System;  
  using   System.Drawing;  
  using   System.Collections;  
  using   System.ComponentModel;  
  using   System.Windows.Forms;  
  using   System.Data;  
  using   System.Runtime.InteropServices;  
  using   System.Drawing.Imaging;  
   
  namespace   CapTureMovie  
  {  
  ///   <summary>  
  ///   Form1   的摘要说明。  
  ///   </summary>  
  public   class   Form1   :   System.Windows.Forms.Form  
  {  
  private   System.Windows.Forms.Button   BtnCapTure;  
  private   System.Windows.Forms.Panel   panel_Vedio;  
  private   int   hHwnd;  
  private   System.Windows.Forms.Button   BtnStop;  
  private   System.Windows.Forms.Label   LbSysMsg;  
  private   System.Windows.Forms.Button   button1;  
   
  public   struct   videohdr_tag  
  {  
  public   byte[]   lpData;  
  public   int   dwBufferLength;  
  public   int   dwBytesUsed;  
  public   int   dwTimeCaptured;  
  public   int   dwUser;  
  public   int   dwFlags;  
  public   int[]   dwReserved;    
   
  }  
  public   delegate   bool   CallBack(int   hwnd,   int   lParam);    
  ///   <summary>  
  ///   必需的设计器变量。  
  ///   </summary>  
  private   System.ComponentModel.Container   components   =   null;  
  [DllImport("avicap32.dll",   CharSet=CharSet.Ansi,   SetLastError=true,   ExactSpelling=true)]  
  public   static   extern   int   capCreateCaptureWindowA([MarshalAs(UnmanagedType.VBByRefStr)]   ref   string   lpszWindowName,   int   dwStyle,   int   x,   int   y,   int   nWidth,   short   nHeight,   int   hWndParent,   int   nID);  
  [DllImport("avicap32.dll",   CharSet=CharSet.Ansi,   SetLastError=true,   ExactSpelling=true)]  
  public   static   extern   bool   capGetDriverDescriptionA(short   wDriver,   [MarshalAs(UnmanagedType.VBByRefStr)]   ref   string   lpszName,   int   cbName,   [MarshalAs(UnmanagedType.VBByRefStr)]   ref   string   lpszVer,   int   cbVer);  
  [DllImport("user32",   CharSet=CharSet.Ansi,   SetLastError=true,   ExactSpelling=true)]  
  public   static   extern   bool   DestroyWindow(int   hndw);  
  [DllImport("user32",   EntryPoint="SendMessageA",   CharSet=CharSet.Ansi,   SetLastError=true,   ExactSpelling=true)]  
  public   static   extern   int   SendMessage(int   hwnd,   int   wMsg,   int   wParam,   [MarshalAs(UnmanagedType.AsAny)]   object   lParam);  
  [DllImport("user32",   CharSet=CharSet.Ansi,   SetLastError=true,   ExactSpelling=true)]  
  public   static   extern   int   SetWindowPos(int   hwnd,   int   hWndInsertAfter,   int   x,   int   y,   int   cx,   int   cy,   int   wFlags);  
  [DllImport("vfw32.dll")]  
  public   static   extern   string   capVideoStreamCallback(int   hwnd,videohdr_tag   videohdr_tag);  
  [DllImport("vicap32.dll",   CharSet=CharSet.Ansi,   SetLastError=true,   ExactSpelling=true)]  
  public   static   extern   bool   capSetCallbackOnFrame(int   hwnd,string   s);  
   
  public   Form1()  
  {  
  //  
  //   Windows   窗体设计器支持所必需的  
  //  
  InitializeComponent();  
   
  //  
  //   TODO:   在   InitializeComponent   调用后添加任何构造函数代码  
  //  
  }  
   
  ///   <summary>  
  ///   清理所有正在使用的资源。  
  ///   </summary>  
  protected   override   void   Dispose(   bool   disposing   )  
  {  
  if(   disposing   )  
  {  
  if   (components   !=   null)    
  {  
  components.Dispose();  
  }  
  }  
  base.Dispose(   disposing   );  
  }  
   
  #region   Windows   窗体设计器生成的代码  
  ///   <summary>  
  ///   设计器支持所需的方法   -   不要使用代码编辑器修改  
  ///   此方法的内容。  
  ///   </summary>  
  private   void   InitializeComponent()  
  {  
  System.Resources.ResourceManager   resources   =   new   System.Resources.ResourceManager(typeof(Form1));  
  this.panel_Vedio   =   new   System.Windows.Forms.Panel();  
  this.BtnCapTure   =   new   System.Windows.Forms.Button();  
  this.BtnStop   =   new   System.Windows.Forms.Button();  
  this.LbSysMsg   =   new   System.Windows.Forms.Label();  
  this.button1   =   new   System.Windows.Forms.Button();  
  this.SuspendLayout();  
  //    
  //   panel_Vedio  
  //    
  this.panel_Vedio.BackgroundImage   =   ((System.Drawing.Image)(resources.GetObject("panel_Vedio.BackgroundImage")));  
  this.panel_Vedio.BorderStyle   =   System.Windows.Forms.BorderStyle.Fixed3D;  
  this.panel_Vedio.Location   =   new   System.Drawing.Point(8,   16);  
  this.panel_Vedio.Name   =   "panel_Vedio";  
  this.panel_Vedio.Size   =   new   System.Drawing.Size(288,   224);  
  this.panel_Vedio.TabIndex   =   0;  
  //    
  //   BtnCapTure  
  //    
  this.BtnCapTure.Location   =   new   System.Drawing.Point(24,   256);  
  this.BtnCapTure.Name   =   "BtnCapTure";  
  this.BtnCapTure.TabIndex   =   1;  
  this.BtnCapTure.Text   =   "图象采集";  
  this.BtnCapTure.Click   +=   new   System.EventHandler(this.BtnCapTure_Click);  
  //    
  //   BtnStop  
  //    
  this.BtnStop.Enabled   =   false;  
  this.BtnStop.Location   =   new   System.Drawing.Point(136,   256);  
  this.BtnStop.Name   =   "BtnStop";  
  this.BtnStop.TabIndex   =   1;  
  this.BtnStop.Text   =   "停止采集";  
  this.BtnStop.Click   +=   new   System.EventHandler(this.BtnStop_Click);  
  //    
  //   LbSysMsg  
  //    
  this.LbSysMsg.Location   =   new   System.Drawing.Point(16,   296);  
  this.LbSysMsg.Name   =   "LbSysMsg";  
  this.LbSysMsg.Size   =   new   System.Drawing.Size(240,   23);  
  this.LbSysMsg.TabIndex   =   2;  
  //    
  //   button1  
  //    
  this.button1.Location   =   new   System.Drawing.Point(304,   48);  
  this.button1.Name   =   "button1";  
  this.button1.TabIndex   =   3;  
  this.button1.Text   =   "button1";  
  this.button1.Click   +=   new   System.EventHandler(this.button1_Click);  
  //    
  //   Form1  
  //    
  this.AutoScaleBaseSize   =   new   System.Drawing.Size(6,   14);  
  this.ClientSize   =   new   System.Drawing.Size(400,   357);  
  this.Controls.Add(this.button1);  
  this.Controls.Add(this.LbSysMsg);  
  this.Controls.Add(this.BtnCapTure);  
  this.Controls.Add(this.panel_Vedio);  
  this.Controls.Add(this.BtnStop);  
  this.Name   =   "Form1";  
  this.Text   =   "Form1";  
  this.ResumeLayout(false);  
   
  }  
  #endregion  
   
  ///   <summary>  
  ///   应用程序的主入口点。  
  ///   </summary>  
  [STAThread]  
  static   void   Main()    
  {  
  Application.Run(new   Form1());  
  }  
   
  private   void   BtnCapTure_Click(object   sender,   System.EventArgs   e)  
  {  
  this.OpenCapture();  
   
  }  
  private   void   OpenCapture()  
  {  
   
  int   intWidth=this.panel_Vedio.Width;  
  int   intHeight=this.panel_Vedio.Height;  
  int   intDevice=0;  
  string   refDevice=intDevice.ToString();  
  hHwnd=Form1.capCreateCaptureWindowA(ref   refDevice,1342177280,0,0,640,480,this.panel_Vedio.Handle.ToInt32(),0);  
  this.LbSysMsg.Text="";  
  this.LbSysMsg.Text+="驱动:"+refDevice;  
  if(Form1.SendMessage(hHwnd,0x40a,intDevice,0)>0)  
  {  
  Form1.SendMessage(this.hHwnd,0x435,-1,   0);  
  Form1.SendMessage(this.hHwnd,0x434,0x42,   0);  
  Form1.SendMessage(this.hHwnd,0x432,-1,   0);  
  Form1.SetWindowPos(this.hHwnd,1,0,0,intWidth,intHeight,6);  
  this.BtnCapTure.Enabled=false;  
  this.BtnStop.Enabled=true;  
  }  
  else  
  {  
  Form1.DestroyWindow(this.hHwnd);  
  this.BtnCapTure.Enabled=false;  
  this.BtnStop.Enabled=true;  
  }  
  }  
   
  private   void   BtnStop_Click(object   sender,   System.EventArgs   e)  
  {  
  Form1.SendMessage(this.hHwnd,   0x40b,   0,   0);  
  Form1.DestroyWindow(this.hHwnd);  
  this.BtnCapTure.Enabled=true;  
  this.BtnStop.Enabled=false;  
  }  
   
  private   void   button1_Click(object   sender,   System.EventArgs   e)  
  {  
  try  
  {  
  Form1.SendMessage(this.hHwnd,0x41e,0,0);  
  IDataObject   obj1   =   Clipboard.GetDataObject();  
  if   (obj1.GetDataPresent(typeof(Bitmap)))  
  {  
                                      Image   image1   =   (Image)   obj1.GetData(typeof(Bitmap));  
                                    //   this.panel_Vedio.Image   =   image1;  
                                    //   this.ClosePreviewWindow();  
                                       
      SaveFileDialog   SaveFileDialog1=new   SaveFileDialog();  
                                      if   (SaveFileDialog1.ShowDialog()   ==   DialogResult.OK)  
                                      {  
                                                  image1.Save(SaveFileDialog1.FileName,   ImageFormat.Bmp);  
                                      }  
    }  
  }  
  catch  
  {  
  }  
  }  
  }  
  }Top

7 楼luckin(aliang)回复于 2006-04-27 16:36:09 得分 0

using   System;  
  using   System.Drawing;  
  using   System.Collections;  
  using   System.ComponentModel;  
  using   System.Windows.Forms;  
  using   System.Data;  
  using   System.Runtime.InteropServices;  
  using   System.Drawing.Imaging;  
   
  namespace   CapTureMovie  
  {  
  ///   <summary>  
  ///   Form1   的摘要说明。  
  ///   </summary>  
  public   class   Form1   :   System.Windows.Forms.Form  
  {  
  private   System.Windows.Forms.Button   BtnCapTure;  
  private   System.Windows.Forms.Panel   panel_Vedio;  
  private   int   hHwnd;  
  private   System.Windows.Forms.Button   BtnStop;  
  private   System.Windows.Forms.Label   LbSysMsg;  
  private   System.Windows.Forms.Button   button1;  
   
  public   struct   videohdr_tag  
  {  
  public   byte[]   lpData;  
  public   int   dwBufferLength;  
  public   int   dwBytesUsed;  
  public   int   dwTimeCaptured;  
  public   int   dwUser;  
  public   int   dwFlags;  
  public   int[]   dwReserved;    
   
  }  
  public   delegate   bool   CallBack(int   hwnd,   int   lParam);    
  ///   <summary>  
  ///   必需的设计器变量。  
  ///   </summary>  
  private   System.ComponentModel.Container   components   =   null;  
  [DllImport("avicap32.dll",   CharSet=CharSet.Ansi,   SetLastError=true,   ExactSpelling=true)]  
  public   static   extern   int   capCreateCaptureWindowA([MarshalAs(UnmanagedType.VBByRefStr)]   ref   string   lpszWindowName,   int   dwStyle,   int   x,   int   y,   int   nWidth,   short   nHeight,   int   hWndParent,   int   nID);  
  [DllImport("avicap32.dll",   CharSet=CharSet.Ansi,   SetLastError=true,   ExactSpelling=true)]  
  public   static   extern   bool   capGetDriverDescriptionA(short   wDriver,   [MarshalAs(UnmanagedType.VBByRefStr)]   ref   string   lpszName,   int   cbName,   [MarshalAs(UnmanagedType.VBByRefStr)]   ref   string   lpszVer,   int   cbVer);  
  [DllImport("user32",   CharSet=CharSet.Ansi,   SetLastError=true,   ExactSpelling=true)]  
  public   static   extern   bool   DestroyWindow(int   hndw);  
  [DllImport("user32",   EntryPoint="SendMessageA",   CharSet=CharSet.Ansi,   SetLastError=true,   ExactSpelling=true)]  
  public   static   extern   int   SendMessage(int   hwnd,   int   wMsg,   int   wParam,   [MarshalAs(UnmanagedType.AsAny)]   object   lParam);  
  [DllImport("user32",   CharSet=CharSet.Ansi,   SetLastError=true,   ExactSpelling=true)]  
  public   static   extern   int   SetWindowPos(int   hwnd,   int   hWndInsertAfter,   int   x,   int   y,   int   cx,   int   cy,   int   wFlags);  
  [DllImport("vfw32.dll")]  
  public   static   extern   string   capVideoStreamCallback(int   hwnd,videohdr_tag   videohdr_tag);  
  [DllImport("vicap32.dll",   CharSet=CharSet.Ansi,   SetLastError=true,   ExactSpelling=true)]  
  public   static   extern   bool   capSetCallbackOnFrame(int   hwnd,string   s);  
   
  public   Form1()  
  {  
  //  
  //   Windows   窗体设计器支持所必需的  
  //  
  InitializeComponent();  
   
  //  
  //   TODO:   在   InitializeComponent   调用后添加任何构造函数代码  
  //  
  }  
   
  ///   <summary>  
  ///   清理所有正在使用的资源。  
  ///   </summary>  
  protected   override   void   Dispose(   bool   disposing   )  
  {  
  if(   disposing   )  
  {  
  if   (components   !=   null)    
  {  
  components.Dispose();  
  }  
  }  
  base.Dispose(   disposing   );  
  }  
   
  #region   Windows   窗体设计器生成的代码  
  ///   <summary>  
  ///   设计器支持所需的方法   -   不要使用代码编辑器修改  
  ///   此方法的内容。  
  ///   </summary>  
  private   void   InitializeComponent()  
  {  
  System.Resources.ResourceManager   resources   =   new   System.Resources.ResourceManager(typeof(Form1));  
  this.panel_Vedio   =   new   System.Windows.Forms.Panel();  
  this.BtnCapTure   =   new   System.Windows.Forms.Button();  
  this.BtnStop   =   new   System.Windows.Forms.Button();  
  this.LbSysMsg   =   new   System.Windows.Forms.Label();  
  this.button1   =   new   System.Windows.Forms.Button();  
  this.SuspendLayout();  
  //    
  //   panel_Vedio  
  //    
  this.panel_Vedio.BackgroundImage   =   ((System.Drawing.Image)(resources.GetObject("panel_Vedio.BackgroundImage")));  
  this.panel_Vedio.BorderStyle   =   System.Windows.Forms.BorderStyle.Fixed3D;  
  this.panel_Vedio.Location   =   new   System.Drawing.Point(8,   16);  
  this.panel_Vedio.Name   =   "panel_Vedio";  
  this.panel_Vedio.Size   =   new   System.Drawing.Size(288,   224);  
  this.panel_Vedio.TabIndex   =   0;  
  //    
  //   BtnCapTure  
  //    
  this.BtnCapTure.Location   =   new   System.Drawing.Point(24,   256);  
  this.BtnCapTure.Name   =   "BtnCapTure";  
  this.BtnCapTure.TabIndex   =   1;  
  this.BtnCapTure.Text   =   "图象采集";  
  this.BtnCapTure.Click   +=   new   System.EventHandler(this.BtnCapTure_Click);  
  //    
  //   BtnStop  
  //    
  this.BtnStop.Enabled   =   false;  
  this.BtnStop.Location   =   new   System.Drawing.Point(136,   256);  
  this.BtnStop.Name   =   "BtnStop";  
  this.BtnStop.TabIndex   =   1;  
  this.BtnStop.Text   =   "停止采集";  
  this.BtnStop.Click   +=   new   System.EventHandler(this.BtnStop_Click);  
  //    
  //   LbSysMsg  
  //    
  this.LbSysMsg.Location   =   new   System.Drawing.Point(16,   296);  
  this.LbSysMsg.Name   =   "LbSysMsg";  
  this.LbSysMsg.Size   =   new   System.Drawing.Size(240,   23);  
  this.LbSysMsg.TabIndex   =   2;  
  //    
  //   button1  
  //    
  this.button1.Location   =   new   System.Drawing.Point(304,   48);  
  this.button1.Name   =   "button1";  
  this.button1.TabIndex   =   3;  
  this.button1.Text   =   "button1";  
  this.button1.Click   +=   new   System.EventHandler(this.button1_Click);  
  //    
  //   Form1  
  //    
  this.AutoScaleBaseSize   =   new   System.Drawing.Size(6,   14);  
  this.ClientSize   =   new   System.Drawing.Size(400,   357);  
  this.Controls.Add(this.button1);  
  this.Controls.Add(this.LbSysMsg);  
  this.Controls.Add(this.BtnCapTure);  
  this.Controls.Add(this.panel_Vedio);  
  this.Controls.Add(this.BtnStop);  
  this.Name   =   "Form1";  
  this.Text   =   "Form1";  
  this.ResumeLayout(false);  
   
  }  
  #endregion  
   
  ///   <summary>  
  ///   应用程序的主入口点。  
  ///   </summary>  
  [STAThread]  
  static   void   Main()    
  {  
  Application.Run(new   Form1());  
  }  
   
  private   void   BtnCapTure_Click(object   sender,   System.EventArgs   e)  
  {  
  this.OpenCapture();  
   
  }  
  private   void   OpenCapture()  
  {  
   
  int   intWidth=this.panel_Vedio.Width;  
  int   intHeight=this.panel_Vedio.Height;  
  int   intDevice=0;  
  string   refDevice=intDevice.ToString();  
  hHwnd=Form1.capCreateCaptureWindowA(ref   refDevice,1342177280,0,0,640,480,this.panel_Vedio.Handle.ToInt32(),0);  
  this.LbSysMsg.Text="";  
  this.LbSysMsg.Text+="驱动:"+refDevice;  
  if(Form1.SendMessage(hHwnd,0x40a,intDevice,0)>0)  
  {  
  Form1.SendMessage(this.hHwnd,0x435,-1,   0);  
  Form1.SendMessage(this.hHwnd,0x434,0x42,   0);  
  Form1.SendMessage(this.hHwnd,0x432,-1,   0);  
  Form1.SetWindowPos(this.hHwnd,1,0,0,intWidth,intHeight,6);  
  this.BtnCapTure.Enabled=false;  
  this.BtnStop.Enabled=true;  
  }  
  else  
  {  
  Form1.DestroyWindow(this.hHwnd);  
  this.BtnCapTure.Enabled=false;  
  this.BtnStop.Enabled=true;  
  }  
  }  
   
  private   void   BtnStop_Click(object   sender,   System.EventArgs   e)  
  {  
  Form1.SendMessage(this.hHwnd,   0x40b,   0,   0);  
  Form1.DestroyWindow(this.hHwnd);  
  this.BtnCapTure.Enabled=true;  
  this.BtnStop.Enabled=false;  
  }  
   
  private   void   button1_Click(object   sender,   System.EventArgs   e)  
  {  
  try  
  {  
  Form1.SendMessage(this.hHwnd,0x41e,0,0);  
  IDataObject   obj1   =   Clipboard.GetDataObject();  
  if   (obj1.GetDataPresent(typeof(Bitmap)))  
  {  
                                      Image   image1   =   (Image)   obj1.GetData(typeof(Bitmap));  
                                    //   this.panel_Vedio.Image   =   image1;  
                                    //   this.ClosePreviewWindow();  
                                       
      SaveFileDialog   SaveFileDialog1=new   SaveFileDialog();  
                                      if   (SaveFileDialog1.ShowDialog()   ==   DialogResult.OK)  
                                      {  
                                                  image1.Save(SaveFileDialog1.FileName,   ImageFormat.Bmp);  
                                      }  
    }  
  }  
  catch  
  {  
  }  
  }  
  }  
  }Top

8 楼LCW010(编程无涯)回复于 2006-04-27 17:32:54 得分 0

studyTop

9 楼Climb_Tree(climbTree@msn.com)回复于 2006-04-27 17:59:08 得分 0

studyTop

相关问题

  • 如何在USB摄像头的预览画面中画线?
  • vfw 控制摄像头录像, 100 分求救,不够再加,谢谢
  • 除了摄像头,和采集卡,有没有USB式的摄像和电脑同步工作录像?
  • 摄像头录像功能嵌入WEB问题。不知道发在这里合适不
  • 摄像头
  • EXCEL一点击预览就死机,怎么回事?
  • 连接摄像头..
  • 关于摄像头
  • 关于摄像头
  • 摄像头问题?

关键词

  • 预览
  • btnstop
  • vedio
  • btncapture
  • lbsysmsg
  • hhwnd
  • panel
  • exactspelling
  • setlasterror
  • intdevice

得分解答快速导航

  • 帖主:cq_lqj
  • luqinjian
  • zlz_212
  • wxdl1981
  • blackhero
  • luckin

相关链接

  • CSDN .NET频道
  • .NET类图书
  • C#类图书
  • .NET类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo