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有图形界面和工具界 ...
随机推荐
- springboot 热部署替代方式
因为使用的 idea springboot2.2.0 snapshot版本, 常规的devtools方法实在是实现不了热部署,所以采用手动update的方法更新,测试可以成功更新resource里面的 ...
- TCP之连接的建立和终止
1. 连接的建立 TCP 连接建立的三次握手 如上图所示,TCP 连接的建立会发生如下述情形: 服务器必须准备好接受外来的连接.这通常通过调用 socket.bind 和 listen 这 3 个函数 ...
- java_切面日志
切面日志举例 package com.keyba1; import java.lang.annotation.ElementType; import java.lang.annotation.Rete ...
- append和push和pop区别
append() 操作的是DOM节点,在被选元素的结尾(内部结尾)插入指定内容: push() 向数组末尾插入一个或者多个元素,并且返回新的长度: pop() 删除 ...
- windows 重启java进程脚本
这个脚本用于启动和重启javaWeb程序 @echo off rem 配置端口号 set port= rem 第一层循环检查端口占用的pid for /f "tokens=5" % ...
- MyBatis Mapper Demo
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-/ ...
- OpenStack 的单元测试
目录 文章目录 目录 前言 单元测试能提高生产率 Python 单元测试工具清单 unittest Test Discover Test Fixture Test Suite Assert(断言) m ...
- Linux 部署 Django 系统
一:安装uwsgi pip3 install uwsgi 二:进入项目目录下,创建uwsgi.ini配置文件 [uwsgi] # 使用nginx连接时使用功能,上线时才使用socket,指定项目执行的 ...
- IDEA的version control log为空,该怎么办?
问题描述: 解决方案: 关掉IDEA,重新打开,即可药到病除
- MVC 表单防伪,自定义提示(AntiForgery.Validate)
再以前的文章解释过@Html.AntiForgeryToken()的部分源码,地址 直奔主题 <form id="form" action=""> ...