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;
没有合适的资源?快使用搜索试试~ 我知道了~
c# Form 摄像头编程,监控,获取图像
共49个文件
cs:10个
exe:6个
txt:6个
4星 · 超过85%的资源 需积分: 10 44 下载量 105 浏览量
2009-12-16
15:25:07
上传
评论 3
收藏 87KB RAR 举报
温馨提示
c# Form摄像头编程,监控,获取图像 程序内无木马和病毒,请放心使用
资源推荐
资源详情
资源评论
收起资源包目录
C# 摄像头编程.rar (49个子文件)
C# 摄像头编程
Webcam
webcam.sln 900B
webcam.csproj 3KB
Form1.cs 5KB
bin
Debug
webcam.pdb 22KB
webcam.exe 24KB
webcam.vshost.exe 6KB
obj
webcam.csproj.FileListAbsolute.txt 797B
Debug
webcam.pdb 22KB
webcam.exe 24KB
webcam.Properties.Resources.resources 180B
webcam.Form1.resources 180B
webcam.csproj.GenerateResource.Cache 842B
TempPE
webcam.csproj.FileList.txt 261B
Properties
Resources.Designer.cs 3KB
Settings.settings 249B
Resources.resx 5KB
Settings.Designer.cs 1KB
AssemblyInfo.cs 1KB
Program.cs 465B
Form1.Designer.cs 4KB
Form1.resx 6KB
webcam.suo 13KB
WindowsApplication3
WindowsApplication3.csproj.user 2KB
Form1.cs 4KB
bin
Debug
WindowsApplication3.vshost.exe.manifest 490B
WindowsApplication3.vshost.exe 14KB
WindowsApplication3.pdb 24KB
WindowsApplication3.exe 24KB
obj
Debug
WindowsApplication3.csproj.GenerateResource.Cache 847B
webcam.Form1.resources 180B
WindowsApplication3.pdb 24KB
WindowsApplication3.Properties.Resources.resources 180B
TempPE
Properties.Resources.Designer.cs.dll 4KB
WindowsApplication3.csproj.FileListAbsolute.txt 995B
WindowsApplication3.exe 24KB
WindowsApplication3.csproj.FileList.txt 339B
Properties
Resources.Designer.cs 3KB
Resources.resx 6KB
WindowsApplication3.sln 922B
webcam.cs 7KB
WindowsApplication3.suo 17KB
App.ico 1KB
Form1.resx 6KB
UpgradeLog2.XML 4KB
UpgradeLog.XML 3KB
WindowsApplication3.csproj 5KB
AssemblyInfo.cs 2KB
1.txt 9KB
2.txt 5KB
共 49 条
- 1
macallkirk
- 粉丝: 2
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- keil2 + proteus + 8051.exe
- 1961ee27df03bd4595d28e24b00dde4e_744c805f7e4fb4d40fa3f695bfbab035_8(1).c
- mediapipe-0.9.0.1-cp37-cp37m-win-amd64.whl.zip
- windows注册表编辑工具
- mediapipe-0.9.0.1-cp37-cp37m-win-amd64.whl.zip
- 校园通行码预约管理系统20240522075502
- 车类型数据集6250张VOC+YOLO格式.zip
- The PyTorch implementation of STGCN.STGCN-main.zip
- 092300108.cpp
- 车类型数据集6000张VOC+YOLO格式.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页