ImageVerifierCode 换一换
格式:DOCX , 页数:50 ,大小:58.93KB ,
资源ID:9461512      下载积分:10 金币
验证码下载
登录下载
邮箱/手机:
图形码:
验证码: 获取验证码
温馨提示:
支付成功后,系统会自动生成账号(用户名为邮箱或者手机号,密码是验证码),方便下次登录下载和查询订单;
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

开通VIP
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.zixin.com.cn/docdown/9461512.html】到电脑端继续下载(重复下载【60天内】不扣币)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

开通VIP折扣优惠下载文档

            查看会员权益                  [ 下载后找不到文档?]

填表反馈(24小时):  下载求助     关注领币    退款申请

开具发票请登录PC端进行申请。


权利声明

1、咨信平台为文档C2C交易模式,即用户上传的文档直接被用户下载,收益归上传人(含作者)所有;本站仅是提供信息存储空间和展示预览,仅对用户上传内容的表现方式做保护处理,对上载内容不做任何修改或编辑。所展示的作品文档包括内容和图片全部来源于网络用户和作者上传投稿,我们不确定上传用户享有完全著作权,根据《信息网络传播权保护条例》,如果侵犯了您的版权、权益或隐私,请联系我们,核实后会尽快下架及时删除,并可随时和客服了解处理情况,尊重保护知识产权我们共同努力。
2、文档的总页数、文档格式和文档大小以系统显示为准(内容中显示的页数不一定正确),网站客服只以系统显示的页数、文件格式、文档大小作为仲裁依据,个别因单元格分列造成显示页码不一将协商解决,平台无法对文档的真实性、完整性、权威性、准确性、专业性及其观点立场做任何保证或承诺,下载前须认真查看,确认无误后再购买,务必慎重购买;若有违法违纪将进行移交司法处理,若涉侵权平台将进行基本处罚并下架。
3、本站所有内容均由用户上传,付费前请自行鉴别,如您付费,意味着您已接受本站规则且自行承担风险,本站不进行额外附加服务,虚拟产品一经售出概不退款(未进行购买下载可退充值款),文档一经付费(服务费)、不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
4、如你看到网页展示的文档有www.zixin.com.cn水印,是因预览和防盗链等技术需要对页面进行转换压缩成图而已,我们并不对上传的文档进行任何编辑或修改,文档下载后都不会有水印标识(原文档上传前个别存留的除外),下载后原文更清晰;试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓;PPT和DOC文档可被视为“模板”,允许上传人保留章节、目录结构的情况下删减部份的内容;PDF文档不管是原文档转换或图片扫描而得,本站不作要求视为允许,下载前可先查看【教您几个在下载文档中可以更好的避免被坑】。
5、本文档所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用;网站提供的党政主题相关内容(国旗、国徽、党徽--等)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
6、文档遇到问题,请及时联系平台进行协调解决,联系【微信客服】、【QQ客服】,若有其他问题请点击或扫码反馈【服务填表】;文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“【版权申诉】”,意见反馈和侵权处理邮箱:1219186828@qq.com;也可以拔打客服电话:4009-655-100;投诉/维权电话:18658249818。

注意事项

本文(C#获取摄像头的几个简单方法.docx)为本站上传会员【仙人****88】主动上传,咨信网仅是提供信息存储空间和展示预览,仅对用户上传内容的表现方式做保护处理,对上载内容不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知咨信网(发送邮件至1219186828@qq.com、拔打电话4009-655-100或【 微信客服】、【 QQ客服】),核实后会尽快下架及时删除,并可随时和客服了解处理情况,尊重保护知识产权我们共同努力。
温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载【60天内】不扣币。 服务填表

C#获取摄像头的几个简单方法.docx

1、有很多C#获取摄像头的实现方法,都是使用已经过时的技术之所以过时,是因为他们还在使用97年被directshow抛弃的摄像头调用类(avicap32.dll), 现在有比较先进一点的资料,大家到Google里面搜索一下吧! 我自己总结了一下,一些C#获取摄像头的方法很好用的,代码比较少的程序提供给大家下载: 1.C#写的简单的摄像头视频获取源代码 camera.rar 2.我自己正在使用的C#获取摄像头程序,代码相当的短(不到100行), 以下系统必备组件是必需的: Windows Installer 3.1 .NET Framework 3.5 Debug.r

2、ar源代码 c# 获取 摄像头 实现录像 利用普通的简易摄像头,通过C#语言即可开发成简易视频程序。本实例利用市场上购买的普通摄像头,利用VFW技术,实现单路视频监控系统。运行程序,窗体中将显示舰体摄像头采集的视频信息。如图13.9所示。 技术要点 本实例主要使用了VFW(Video for Windows)技术。VFW 是Microsoft公司为开发Windows平台下的视频应用程序提供的软件工具包,提供了一系列应用程序编程接口(API),用户可以通过这些接口很方便地实现视频捕获、视频编辑及视频播放等通用功能,还可利用回调函数开发比较复杂的视频应用程序。该技术的特点是播

3、放视频时不需要专用的硬件设备,而且应用灵活,可以满足视频应用程序开发的需要。Windows操作系统自身就携带了VFW技术,系统安装时,会自动安装VFW的相关组件。 VFW技术主要由六个功能模块组成,下面进行简单说明。 AVICAP32.DLL:包含执行视频捕获的函数,给AVI文件的I/O处理和视频,音频设备驱动程序提供一个高级接口。 MSVIDEO.DLL:包含一套特殊的DrawDib函数,用来处理程序上的视频操作。 MCIAVI.DRV:包括对VFW的MCI命令解释器的驱动程序。 AVIFILE.DLL:包含由标准多媒体I/O(mmio)函数提供的更高级的命令,用来访问.AVI文件

4、 ICM:压缩管理器,用于管理的视频压缩/解压缩的编译码器。 ACM:音频压缩管理器,提供与ICM相似的服务,适用于波形音频。 AVICAP32.DLL中的函数和USER32.DLL中的函数,函数语法及结构如下。 (1)capCreateCaptureWindow函数 该函数用于创建一个视频捕捉窗口。语法如下: [DllImport("avicap32.dll")] public static extern IntPtr capCreateCaptureWindowA(byte[] lpszWindowName, int dwStyle, int x, int y, int n

5、Width, int nHeight, IntPtr hWndParent, int nID); 参数说明如下。 lpszWindowName:标识窗口的名称。 dwStyle:标识窗口风格。 x、y:标识窗口的左上角坐标。 nWidth、nHeight:标识窗口的宽度和高度。 hWnd:标识父窗口句柄。 nID:标识窗口ID。 返回值:视频捕捉窗口句柄。 (2)SendMessage函数 用于向Windows系统发送消息机制。 [DllImport("User32.dll")] private static extern bool SendMessage(IntPtr

6、 hWnd, int wMsg, int wParam, int lParam); 参数说明如下。 hWnd:窗口句柄。 wMsg:将要发送的消息。 wParam、lParam:消息的参数,每个消息都有两个参数,参数设置由发送的消息而定。 Form1窗体中通过调用视频类中的方法来实现相应的功能。 在【开始录像】按钮的Click事件中添加如下代码: private void buttonStart_Click(object sender, EventArgs e) { buttonStart.Enabled = false; buttonStop.Enabled = true

7、 //btnPz.Enabled = true; video = new cVideo(picCapture.Handle, picCapture.Width, picCapture.Height); video.StartWebCam(); } 在【停止录像】按钮的Click事件中添加如下代码: private void buttonStop_Click(object sender, EventArgs e) { buttonStart.Enabled = true; buttonStop.Enabled = false; buttonPz.Enabled = fals

8、e; video.CloseWebcam(); } 在【拍照】按钮的Click事件下添加如下代码: private void buttonPz_Click(object sender, EventArgs e) { video.GrabImage(picCapture.Handle, "d:\\a.bmp"); } 完整代码如下: 1、Program.cs using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace V

9、ideo1 { static class Program { ///

/// 应用程序的主入口点。 /// [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } } } 2、Form1.cs using System; using System.Collections.

10、Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace Video1 { public partial class Form1 : Form { cVideo video; public Form1() { InitializeComponent(); } private void buttonStart_Cli

11、ck(object sender, EventArgs e) { buttonStart.Enabled = false; buttonStop.Enabled = true; //btnPz.Enabled = true; video = new cVideo(picCapture.Handle, picCapture.Width, picCapture.Height); video.StartWebCam(); } private void buttonStop_Click(object sender, EventArgs e) { buttonStart.Enable

12、d = true; buttonStop.Enabled = false; buttonPz.Enabled = false; video.CloseWebcam(); } private void buttonPz_Click(object sender, EventArgs e) { video.GrabImage(picCapture.Handle, "d:\\a.bmp"); } } } 3、Form1.Designer.cs namespace Video1 { partial class Form1 { ///

/// 必需的设

13、计器变量。 ///

private System.ComponentModel.IContainer components = null; /// /// 清理所有正在使用的资源。 /// /// 如果应释放托管资源,为 true;否则为 false。 protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); }

14、 base.Dispose(disposing); } #region Windows 窗体设计器生成的代码 ///

/// 设计器支持所需的方法 - 不要 /// 使用代码编辑器修改此方法的内容。 /// private void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); t

15、his.buttonStart = new System.Windows.Forms.Button(); this.buttonStop = new System.Windows.Forms.Button(); this.buttonPz = new System.Windows.Forms.Button(); this.panelTop = new System.Windows.Forms.Panel(); this.picCapture = new System.Windows.Forms.PictureBox(); this.panelBottom = new System.W

16、indows.Forms.Panel(); this.panelTop.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.picCapture)).BeginInit(); this.panelBottom.SuspendLayout(); this.SuspendLayout(); // // buttonStart // this.buttonStart.Location = new System.Drawing.Point(39, 3); this.buttonStart.Name =

17、 "buttonStart"; this.buttonStart.Size = new System.Drawing.Size(88, 36); this.buttonStart.TabIndex = 1; this.buttonStart.Text = "开始录像"; this.buttonStart.UseVisualStyleBackColor = true; this.buttonStart.Click += new System.EventHandler(this.buttonStart_Click); // // buttonStop // this.butt

18、onStop.Location = new System.Drawing.Point(181, 3); this.buttonStop.Name = "buttonStop"; this.buttonStop.Size = new System.Drawing.Size(80, 36); this.buttonStop.TabIndex = 2; this.buttonStop.Text = "停止录像"; this.buttonStop.UseVisualStyleBackColor = true; this.buttonStop.Click += new System.Even

19、tHandler(this.buttonStop_Click); // // buttonPz // this.buttonPz.Location = new System.Drawing.Point(313, 3); this.buttonPz.Name = "buttonPz"; this.buttonPz.Size = new System.Drawing.Size(77, 36); this.buttonPz.TabIndex = 3; this.buttonPz.Text = "拍 照"; this.buttonPz.UseVisualStyleBackColo

20、r = true; this.buttonPz.Click += new System.EventHandler(this.buttonPz_Click); // // panelTop // this.panelTop.AutoSize = true; this.panelTop.Controls.Add(this.picCapture); this.panelTop.Dock = System.Windows.Forms.DockStyle.Fill; this.panelTop.Location = new System.Drawing.Point(0, 0); t

21、his.panelTop.Name = "panelTop"; this.panelTop.Size = new System.Drawing.Size(468, 372); this.panelTop.TabIndex = 4; // // picCapture // this.picCapture.Dock = System.Windows.Forms.DockStyle.Fill; this.picCapture.InitialImage = ((System.Drawing.Image)(resources.GetObject("picCapture.InitialI

22、mage"))); this.picCapture.Location = new System.Drawing.Point(0, 0); this.picCapture.Name = "picCapture"; this.picCapture.Size = new System.Drawing.Size(468, 372); this.picCapture.TabIndex = 0; this.picCapture.TabStop = false; // // panelBottom // this.panelBottom.Controls.Add(this.button

23、Start); this.panelBottom.Controls.Add(this.buttonStop); this.panelBottom.Controls.Add(this.buttonPz); this.panelBottom.Dock = System.Windows.Forms.DockStyle.Bottom; this.panelBottom.Location = new System.Drawing.Point(0, 327); this.panelBottom.Name = "panelBottom"; this.panelBottom.Size = new

24、System.Drawing.Size(468, 45); this.panelBottom.TabIndex = 5; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(468, 372); this.Controls.Add(this.panelBottom);

25、 this.Controls.Add(this.panelTop); this.Name = "Form1"; this.Text = "Form1"; this.panelTop.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.picCapture)).EndInit(); this.panelBottom.ResumeLayout(false); this.ResumeLayout(false); this.PerformLayout(); } #endregion privat

26、e System.Windows.Forms.PictureBox picCapture; private System.Windows.Forms.Button buttonStart; private System.Windows.Forms.Button buttonStop; private System.Windows.Forms.Button buttonPz; private System.Windows.Forms.Panel panelTop; private System.Windows.Forms.Panel panelBottom; } } 4、Clas

27、sVideoAPI.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Drawing; using System.Runtime.InteropServices; using System.Threading; using System.Windows.Forms; using System.IO; namespace Video1 { public class VideoAPI //视频API类 { // 视频A

28、PI调用 [DllImport("avicap32.dll")]//包含了执行视频捕获的函数,它给AVI文件I/O和视频、音频设备驱动程序提供一个高级接口 public static extern IntPtr capCreateCaptureWindow(string lpszWindowName, int dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hwndParent, int nID); [DllImport("AVICAP32.dll", CharSet = CharSet.Unicode)] public s

29、tatic extern bool capGetDriverDescription(int wDriverIndex, StringBuilder lpszName, int cbName, StringBuilder lpszVer, int cbVer); [DllImport("avicap32.dll")] public static extern IntPtr capCreateCaptureWindowA(byte[] lpszWindowName, int dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hWndP

30、arent, int nID); [DllImport("avicap32.dll")] public static extern bool capGetDriverDescriptionA(short wDriver, byte[] lpszName, int cbName, byte[] lpszVer, int cbVer); [DllImport("User32.dll")] public static extern bool SendMessage(IntPtr hWnd, int wMsg, bool wParam, int lParam); [DllImport("Us

31、er32.dll")] public static extern bool SendMessage(IntPtr hWnd, int wMsg, short wParam, int lParam); [DllImport("User32.dll")] public static extern bool SendMessage(IntPtr hWnd, int wMsg, int wParam, int lParam); [DllImport("User32.dll")] public static extern bool SendMessage(IntPtr hWnd, int wM

32、sg, short wParam, FrameEventHandler lParam); [DllImport("User32.dll")] public static extern bool SendMessage(IntPtr hWnd, int wMsg, int wParam, ref BITMAPINFO lParam); [DllImport("User32.dll")] public static extern bool SendMessage(IntPtr hWnd, int wMsg, int wParam, ref CAPDRIVERCAPS lParam); [

33、DllImport("User32.dll")] public static extern bool SendMessage(IntPtr hWnd, int wMsg, int wParam, ref CAPTUREPARMS lParam); [DllImport("User32.dll")] public static extern bool SendMessage(IntPtr hWnd, int wMsg, int wParam, ref CAPSTATUS lParam); [DllImport("User32.dll")] public static extern in

34、t SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int y, int cx, int cy, int wFlags); [DllImport("avicap32.dll")] public static extern int capGetVideoFormat(IntPtr hWnd, IntPtr psVideoFormat, int wSize); // 常量 // public const int WM_USER = 0x400; public const int WS_CHILD = 0x40000000; p

35、ublic const int WS_VISIBLE = 0x10000000; public const int SWP_NOMOVE = 0x2; public const int SWP_NOZORDER = 0x4; // public const int WM_CAP_DRIVER_CONNECT = WM_USER + 10; // public const int WM_CAP_DRIVER_DISCONNECT = WM_USER + 11; public const int WM_CAP_SET_CALLBACK_FRAME = WM_USER + 5; // p

36、ublic const int WM_CAP_SET_PREVIEW = WM_USER + 50; // public const int WM_CAP_SET_PREVIEWRATE = WM_USER + 52; // public const int WM_CAP_SET_VIDEOFORMAT = WM_USER + 45; // public const int WM_CAP_START = WM_USER; public const int WM_CAP_SAVEDIB = WM_CAP_START + 25; public const string avicap32

37、 "avicap32.dll"; public const int WM_USER = 1024; ///

///WM_CAP_START=WM_USER=1024 /// public const int WM_CAP_START = WM_USER; // start of unicode messages /// /// 开始 WM_USER + 100=1124 /// public const int WM_CAP_UNICODE_START = WM_USER + 100; /

38、/开始 1124 ///

/// /获得 CAPSTR EAMPTR /// WM_CAP_START + 1=1025 /// public const int WM_CAP_GET_CAPSTREAMPTR = (WM_CAP_START + 1); //获得 CAPSTR EAMPTR /// /// 设置收回错误 WM_CAP_START + 2=1026 /// public const int WM_CAP_SET_CALLBACK_ERROR = (WM_CAP_START +

39、 2); //设置收回错误 ///

/// 设置收回状态 WM_CAP_START + 3=1027 /// public const int WM_CAP_SET_CALLBACK_STATUS = (WM_CAP_START + 3); //设置收回状态 /// /// 设置收回出产 WM_CAP_START + 4=1028 /// public const int WM_CAP_SET_CALLBACK_YIELD = (WM_CAP_START + 4); //设置收回出产 ///

40、

/// 设置收回结构 WM_CAP_START + 5=1029 /// public const int WM_CAP_SET_CALLBACK_FRame = (WM_CAP_START + 5); //设置收回结构 /// /// 设置收回视频流 WM_CAP_START + 6=1030 /// public const int WM_CAP_SET_CALLBACK_VIDEOSTREAM = (WM_CAP_START + 6); //设置收回视频流 /// /

41、// 设置收回视频波流 WM_CAP_START +7=1031 ///

public const int WM_CAP_SET_CALLBACK_WAVESTREAM = (WM_CAP_START + 7); //设置收回视频波流 /// /// 获得使用者数据 WM_CAP_START + 8=1032 /// public const int WM_CAP_GET_USER_DATA = (WM_CAP_START + 8); //获得使用者数据 /// /// 设置使用者数据 WM_C

42、AP_START + 9=1033 ///

public const int WM_CAP_SET_USER_DATA = (WM_CAP_START + 9); //设置使用者数据 /// /// 驱动程序连接 WM_CAP_START + 10=1034 /// public const int WM_CAP_DRIVER_CONNECT = (WM_CAP_START + 10); //驱动程序连接 /// /// 断开启动程序连接 WM_CAP_START + 11=1035 ///

43、

public const int WM_CAP_DRIVER_DISCONNECT = (WM_CAP_START + 11); //断开启动程序连接 /// /// 获得驱动程序名字 WM_CAP_START + 12=1036 /// public const int WM_CAP_DRIVER_GET_NAME = (WM_CAP_START + 12); //获得驱动程序名字 /// /// 获得驱动程序版本 WM_CAP_START + 13=1037 ///

44、public const int WM_CAP_DRIVER_GET_VERSION = (WM_CAP_START + 13); //获得驱动程序版本 ///

/// 获得驱动程序帽子 WM_CAP_START + 14=1038 /// public const int WM_CAP_DRIVER_GET_CAPS = (WM_CAP_START + 14); //获得驱动程序帽子 /// /// 设置捕获文件 WM_CAP_START + 20=1044 /// public const

45、int WM_CAP_FILE_SET_CAPTURE_FILE = (WM_CAP_START + 20); //设置捕获文件 ///

/// 获得捕获文件 WM_CAP_START + 21=1045 /// public const int WM_CAP_FILE_GET_CAPTURE_FILE = (WM_CAP_START + 21); //获得捕获文件 /// /// 另存文件为 WM_CAP_START + 23=1047 /// public const int WM_CAP_

46、FILE_SAVEAS = (WM_CAP_START + 23); //另存文件为 ///

/// 保存文件 WM_CAP_START + 25=1049 /// public const int WM_CAP_FILE_SAVEDIB = (WM_CAP_START + 25); //保存文件 // out of order to save on ifdefs /// /// 分派文件 WM_CAP_START + 22=1044 /// public const int WM_CAP_F

47、ILE_ALLOCATE = (WM_CAP_START + 22); //分派文件 ///

/// 设置开始文件 WM_CAP_START + 24=1046 /// public const int WM_CAP_FILE_SET_INFOCHUNK = (WM_CAP_START + 24); //设置开始文件 /// /// 编辑复制 WM_CAP_START + 30=1054 /// public const int WM_CAP_EDIT_COPY = (WM_CAP_START

48、 30); //编辑复制 ///

/// 设置音频格式 WM_CAP_START + 35=1059 /// public const int WM_CAP_SET_AUDIOFORMAT = (WM_CAP_START + 35); //设置音频格式 /// /// 捕获音频格式 WM_CAP_START + 36=1060 /// public const int WM_CAP_GET_AUDIOFORMAT = (WM_CAP_START + 36); //捕获音频格式 ///

49、mmary> /// 打开视频格式设置对话框 WM_CAP_START + 41=1065 /// public const int WM_CAP_DLG_VIDEOFORMAT = (WM_CAP_START + 41); //1065 打开视频格式设置对话框 ///

/// 打开属性设置对话框,设置对比度、亮度等 WM_CAP_START + 42=1066 /// public const int WM_CAP_DLG_VIDEOSOURCE = (WM_CAP_START + 42); //1066 打开属性

50、设置对话框,设置对比度、亮度等。 ///

/// 打开视频显示 WM_CAP_START + 43=1067 /// public const int WM_CAP_DLG_VIDEODISPLAY = (WM_CAP_START + 43); //1067 打开视频显示 /// /// 获得视频格式 WM_CAP_START + 44=1068 /// public const int WM_CAP_GET_VIDEOFORMAT = (WM_CAP_START + 44); //1068 获

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2025 宁波自信网络信息技术有限公司  版权所有

客服电话:4009-655-100  投诉/维权电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服