c# 简单打开关闭摄像头
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# 简单打开关闭摄像头的更多相关文章
- h5 Video打开本地摄像头和离开页面关闭摄像头
<div> <video id="video" style="width=100%; height=100%; object-fit: fill&quo ...
- Python-webbrowser实现自动打开关、定时打开关闭网页/刷新网页
webbrowser- 方便的Web浏览器控制器,是Python一个模块,可实现自动打开关.定时打开关闭网页/刷新网页,在Unix下,图形浏览器在X11下更受欢迎,但如果图形浏览器不可用或X11显示器 ...
- WebRTC打开本地摄像头
本文使用WebRTC的功能,打开电脑上的摄像头,并且把摄像头预览到的图像显示出来. 纯网页实现,能支持除IE外的多数浏览器.手机浏览器也可用. 引入依赖 我们需要引入adapter-latest.js ...
- 通过暗码去打开/关闭usb debug开关
通过暗码去打开/关闭usb debug开关 通过暗码去打开/关闭usb debug开关1. Description2. Analysis3. Solution4. Summary 1. Descrip ...
- CentOS7使用firewalld打开关闭防火墙与端口(转载)
1.firewalld的基本使用 启动: systemctl start firewalld 查看状态: systemctl status firewalld 停止: systemctl disabl ...
- fopen(),fclose() 打开/关闭文件
打开/关闭/刷新流 1. fopen() 打开流 功能: 1)fopen()打开由 path指定的一个文件. 2)fdopen()获取一个先有的文件描述符,并使一个标准的I/O流与该描述相结合.此函数 ...
- activity的打开关闭动画
Activity的打开关闭或者说相互跳转之间可以设置动画的.默认的打开关闭直接消失或出现,比较不优美,但是有的手机Rom对这个默认做了修改,比如红米HM1,默认的就是新页面自右向左滑动出现,自左向右滑 ...
- 调用opencv打开不摄像头
调用opencv打开不摄像头,可以试试下面的语句: CvCapture* pCapture = cvCreateCameraCapture(0); 参数设为0 ,而不是-1,在自己电脑上可以 .
- 关于学习CentOS7使用firewalld打开关闭防火墙和端口
1.firewalld简介 firewalld是centos7的一大特点,主要有两个优点:一是支持动态更新,不需要重启服务:二就是加入了防火墙的“zone”概念. firewalld有图形界面和工具界 ...
随机推荐
- 忘记Linux 3.X/4.x/5.x 宝塔面板密码的解决方案
进入ssh 输入以下命令重置密码(把命令最后面的 “testpasswd” 替换成你要改的新密码)注:若是debian/ubuntu用户,请使用有root权限的账户去执行这条命令 cd /www ...
- python:将numpy数组写入csv文件
import numpy as np np.savetxt('E:\\forpython\\featvector.csv',data_to_save,delimiter=',')
- ant DatePicker 中文
方式一:局部设置 import 'moment/locale/zh-cn'; import locale from 'antd/lib/date-picker/locale/zh_CN'; //调用时 ...
- ValueStack对象
ValueStack, 即值栈对象. 值栈对象: 是整个struts数据存储的核心,或者叫中转站. 用户每次访问struts的action,都会创建一个Action对象.值栈对象.ActionCont ...
- css实现左侧固定宽度,右侧宽度自适应
#centerDIV { height: 550px; width: 100%; } #mainDIV { height: 100%; border: 1px solid #F00; margin-l ...
- 在本地局域网 windows server 2008 下安装 Nginx 1.12.1
简介: Nginx ("engine x") 是高性能 HTTP.反向代理服务器,也是 IMAP/POP3/SMTP 代理服务器. Nginx 是由 Igor Sysoev 为俄罗 ...
- 五十九:Flask.Cookie之flask设置cookie过期时间
设置cookie有效期1.max_age:距离现在多少秒后过期,在IE8以下不支持2.expires:datatime类型,使用此参数,需参照格林尼治时间,即北京时间-8个小时3.如果max_age和 ...
- postman提交数组格式方式
提交数组格式数据,对应的服务器端接收的是@RequestBody 和对应的接收值
- Kibana 创建索引 POST 403 (forbidden) on create index
一.问题描述: Kibana创建索引:kibana > management > index patterns > create index pattern 索引名称: mercha ...
- for循环使用
cat > a.sh <<EOF #!/bin/bash export NODE_NAMES=(kube-test1 kube-test2 kube-test3 kube-test4 ...