const short WM_CAP = 1024;
const int WM_CAP_DRIVER_CONNECT = WM_CAP + 10;
const int WM_CAP_DRIVER_DISCONNECT = WM_CAP + 11;
const int WM_CAP_EDIT_COPY = WM_CAP + 30;
const int WM_CAP_SET_PREVIEW = WM_CAP + 50;
const int WM_CAP_SET_PREVIEWRATE = WM_CAP + 52;
const int WM_CAP_SET_SCALE = WM_CAP + 53;
const int WS_CHILD = 0x40000000;
const int WS_VISIBLE = 0x10000000;
const short SWP_NOMOVE = 2;
const short SWP_NOSIZE = 1;
const short SWP_NOZORDER = 4;
const short HWND_BOTTOM = 1;
int iDevice = 0;
int hHwnd; [System.Runtime.InteropServices.DllImport("user32", EntryPoint = "SendMessageA")]
static extern int SendMessage(int hwnd, int wMsg, int wParam, [MarshalAs(UnmanagedType.AsAny)]
object lParam);
[System.Runtime.InteropServices.DllImport("user32", EntryPoint = "SetWindowPos")]
static extern int SetWindowPos(int hwnd, int hWndInsertAfter, int x, int y, int cx, int cy, int wFlags);
[System.Runtime.InteropServices.DllImport("user32")]
static extern bool DestroyWindow(int hndw);
[System.Runtime.InteropServices.DllImport("avicap32.dll")]
static extern int capCreateCaptureWindowA(string lpszWindowName, int dwStyle, int x, int y, int nWidth, int nHeight, int hWndParent, int nID);
[System.Runtime.InteropServices.DllImport("avicap32.dll")]
static extern bool capGetDriverDescriptionA(short wDriver, string lpszName, int cbName, string lpszVer, int cbVer); private void OpenPreviewWindow()
{ int iHeight = 600;
int iWidth = 800; //
// Open Preview window in picturebox
//
hHwnd = capCreateCaptureWindowA(iDevice.ToString(), (WS_VISIBLE | WS_CHILD), 0, 0, iWidth, iHeight, picCapture.Handle.ToInt32(), 0); //
// Connect to device
//
if (SendMessage(hHwnd, WM_CAP_DRIVER_CONNECT, iDevice, 0) == 1)
{
//
// Set the preview scale
//
SendMessage(hHwnd, WM_CAP_SET_SCALE, 1, 0);
//
// Set the preview rate in milliseconds
//
SendMessage(hHwnd, WM_CAP_SET_PREVIEWRATE, 66, 0);
//
// Start previewing the image from the camera
//
SendMessage(hHwnd, WM_CAP_SET_PREVIEW, 1, 0);
//
// Resize window to fit in picturebox
//
SetWindowPos(hHwnd, HWND_BOTTOM, 0, 0, iWidth, iHeight, (SWP_NOMOVE | SWP_NOZORDER));
}
else
{
//
// Error connecting to device close window
//
DestroyWindow(hHwnd);
}
} private void ClosePreviewWindow()
{
//
// Disconnect from device
//
SendMessage(hHwnd, WM_CAP_DRIVER_DISCONNECT, iDevice, 0); //
// close window
//
DestroyWindow(hHwnd);
} private void button1_Click(object sender, EventArgs e)
{ iDevice = 0;// int.Parse(device_number_textBox.Text); OpenPreviewWindow(); }

  

c# 简单打开关闭摄像头的更多相关文章

  1. h5 Video打开本地摄像头和离开页面关闭摄像头

    <div> <video id="video" style="width=100%; height=100%; object-fit: fill&quo ...

  2. Python-webbrowser实现自动打开关、定时打开关闭网页/刷新网页

    webbrowser- 方便的Web浏览器控制器,是Python一个模块,可实现自动打开关.定时打开关闭网页/刷新网页,在Unix下,图形浏览器在X11下更受欢迎,但如果图形浏览器不可用或X11显示器 ...

  3. WebRTC打开本地摄像头

    本文使用WebRTC的功能,打开电脑上的摄像头,并且把摄像头预览到的图像显示出来. 纯网页实现,能支持除IE外的多数浏览器.手机浏览器也可用. 引入依赖 我们需要引入adapter-latest.js ...

  4. 通过暗码去打开/关闭usb debug开关

    通过暗码去打开/关闭usb debug开关 通过暗码去打开/关闭usb debug开关1. Description2. Analysis3. Solution4. Summary 1. Descrip ...

  5. CentOS7使用firewalld打开关闭防火墙与端口(转载)

    1.firewalld的基本使用 启动: systemctl start firewalld 查看状态: systemctl status firewalld 停止: systemctl disabl ...

  6. fopen(),fclose() 打开/关闭文件

    打开/关闭/刷新流 1. fopen() 打开流 功能: 1)fopen()打开由 path指定的一个文件. 2)fdopen()获取一个先有的文件描述符,并使一个标准的I/O流与该描述相结合.此函数 ...

  7. activity的打开关闭动画

    Activity的打开关闭或者说相互跳转之间可以设置动画的.默认的打开关闭直接消失或出现,比较不优美,但是有的手机Rom对这个默认做了修改,比如红米HM1,默认的就是新页面自右向左滑动出现,自左向右滑 ...

  8. 调用opencv打开不摄像头

    调用opencv打开不摄像头,可以试试下面的语句: CvCapture* pCapture = cvCreateCameraCapture(0); 参数设为0 ,而不是-1,在自己电脑上可以 .

  9. 关于学习CentOS7使用firewalld打开关闭防火墙和端口

    1.firewalld简介 firewalld是centos7的一大特点,主要有两个优点:一是支持动态更新,不需要重启服务:二就是加入了防火墙的“zone”概念. firewalld有图形界面和工具界 ...

随机推荐

  1. javascript中“use strict”的好处和坏处

    1.为什么使用严格模式? 消除javascript语法的一些不合理.不严谨之处,减少一些怪异行为: 消除代码运行的不安全之处,保证代码的运行: 提高编译效率,增加运行效率: 为未来新版本的javasc ...

  2. Oracle Stream 同步数据

    1 引言     Oracle官方网: http://www.stanford.edu/dept/itss/docs/oracle/10g/server.101/b10727/strmover.htm ...

  3. 显示和隐藏(display属性)

    网页中经常会看到显示和隐藏的效果,可通过display属性来设置. 语法: Object.style.display = value 注意:Object是获取的元素对象,如通过document.get ...

  4. js window事件解析(转载)

    js-window对象的方法和属性资料 hxpd 发表于 2007-05-08 21:58:18 熟练window对象的open.close.alert.confirm.prompt.setTimeo ...

  5. Torvalds的linux

    1991年,芬兰人林纳斯•托瓦兹在赫尔辛基大学上学,对操作系统很好奇,并且对MINIX只允许在教育上使用很不满(其不允许任何商业使用),于是开始写他自己的操作系统,这就是后来的Linux内核. 199 ...

  6. Service-stack.redis 使用PooledRedisClientManager 速度慢的原因之一

    现在越来越多的开发者使用service-stack.redis 来进行redis的访问,但是获取redisclient的方式有多种方式,其中有一种从缓冲池获取client的方式很是得到大家的认可. L ...

  7. 五十:数据库之Flask-Script详解

    使用flask-script可以实现自定义命令来操作flask,如:可以通过命令来跑一个开发版本的服务器.设置数据库.定时任务等安装:pip install flask-script 命令的添加方式1 ...

  8. springboot中静态属性/静态方法从YAML(yml)读取配置属性

    启动类添加注解@EnableConfigurationProperties import jnetman.session.SnmpPref; import org.springframework.bo ...

  9. ELK 日志平台构建

    elastic中文社区 https://elasticsearch.cn/ 完整参考 ELK实时日志分析平台环境部署--完整记录 https://www.cnblogs.com/kevingrace/ ...

  10. Java:面向对象(继承,方法的重写(overide),super,object类及object类中方法的重写,父子类代码块执行顺序)

    继承: 1.继承是对某一匹类的抽象,从而实现对现实世界更好的建模. 2.提高代码的复用性. 3.extends(扩展),子类是父类的扩展. 4.子类继承父类可以得到父类的全部属性和方法.(除了父类的构 ...