博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
发个小程序希望有人需要(操作摄像头)
阅读量:2286 次
发布时间:2019-05-09

本文共 3815 字,大约阅读时间需要 12 分钟。

来自:http://bbs.csdn.net/topics/320216425

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Runtime.InteropServices;namespace WindowsFormsApplication24{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }              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 = 1073741824;        const int WS_VISIBLE = 268435456;        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, short 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 = 320;            int iWidth = 200;            //             //  Open Preview window in picturebox            //             hHwnd = capCreateCaptureWindowA(iDevice.ToString(), (WS_VISIBLE | WS_CHILD), 0, 0, 640, 480, 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 = int.Parse(device_number_textBox.Text);            OpenPreviewWindow();        }    }}
picCapture为一个PictureBox
device_number_textBox.Text=0为一个TextBox,值为0

转载地址:http://sounb.baihongyu.com/

你可能感兴趣的文章
15天内4面阿里,成功拿下offer,分享个人面经
查看>>
万字长文,带你深入浅出五种负载均衡策略。
查看>>
看图搞懂微服务架构
查看>>
详解:java工具之解析yaml文件
查看>>
包教包会:搭建RocketMQ双主双从同步集群,
查看>>
5年Java程序员,五面蚂蚁险拿offer定级P7,大厂面试不过如此?
查看>>
大厂面试必问!HashMap 怎样解决hash冲突?
查看>>
面试屡屡碰壁,痛定思痛闭关修炼!半年后4面阿里成功拿offer
查看>>
最全的大厂最新面试249题与笔记总结:多线程+JVM +Spring+微服务+分布式+Redis+MySQL
查看>>
吊!设计模式全解:6大设计原则+23种设计模式+设计模式PK+设计模式混编
查看>>
服!看完阿里大牛手写的Java异步编程实战笔记,我惊呆了
查看>>
Java程序员跳槽,三面之后被拒,原因竟是“招不起”
查看>>
想要彻底搞懂微服务架构?必先学:SpringBoot+SpringCloud+docker
查看>>
6天面试10家,已经拿到offer,Java程序员的面试总结分享
查看>>
渣本的逆袭之路!备战3个月,三面蚂蚁金服成功斩获Offer
查看>>
10月末美团、滴滴、蘑菇街9次面试总结(Java岗)
查看>>
热气腾腾的腾讯后台开发面经(总共五面)
查看>>
深入理解设计模式(设计原则+种设计模式+设计模式PK+设计模式混编)
查看>>
谷歌大佬回国发展,吊打各大厂面试官!吐血总结大厂面试高频点及笔记解析
查看>>
面试复盘:面完字节、美团、阿里等大厂,今年面试到底问什么?
查看>>