TVideoCapture类的源码,继承TCustomPanel,用于视频捕获(用到了SendMessage和SetWindowPos等API)good
- unit VideoCapture;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
- Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls, Vcl.Imaging.jpeg;
- type
- TVideoCapture = class(TCustomPanel)
- private
- hWndC: THandle;
- CapturingAVI: bool;
- procedure WMSize(var Message: TWMSize); message WM_SIZE;
- protected
- { Protected declarations }
- public
- constructor Create(AOwner: TComponent); override;
- destructor Destroy; override;
- procedure OpenVideo(handle: THandle);
- procedure CloseVideo;
- procedure GrabFrame;
- procedure StartVideo;
- procedure StopVideo;
- procedure SaveBitMap(filename: TFileName);
- procedure SaveJpeg(filename: TFileName; compressibility: Integer);
- procedure SavetoJpegStream(var JpegStream: TMemoryStream; compressibility: Integer);
- function StartAvi(filename: TFileName): Boolean;
- procedure StopAvi;
- procedure SetVideoFormat;
- procedure SetSource;
- procedure SetStretch(TrueorFalse: Boolean = true);
- procedure SetCompression;
- published
- property Align;
- end;
- procedure Register;
- implementation
- const
- WM_CAP_START = WM_USER;
- WM_CAP_GET_CAPSTREAMPTR = (WM_CAP_START + 1);
- WM_CAP_SET_CALLBACK_ERROR = (WM_CAP_START + 2);
- WM_CAP_SET_CALLBACK_STATUS = (WM_CAP_START + 3);
- WM_CAP_SET_CALLBACK_YIELD = (WM_CAP_START + 4);
- WM_CAP_SET_CALLBACK_FRAME = (WM_CAP_START + 5);
- WM_CAP_SET_CALLBACK_VIDEOSTREAM = (WM_CAP_START + 6);
- WM_CAP_SET_CALLBACK_WAVESTREAM = (WM_CAP_START + 7);
- WM_CAP_GET_USER_DATA = (WM_CAP_START + 8);
- WM_CAP_SET_USER_DATA = (WM_CAP_START + 9);
- WM_CAP_DRIVER_CONNECT = (WM_CAP_START + 10);
- WM_CAP_DRIVER_DISCONNECT = (WM_CAP_START + 11);
- WM_CAP_DRIVER_GET_NAME = (WM_CAP_START + 12);
- WM_CAP_DRIVER_GET_VERSION = (WM_CAP_START + 13);
- WM_CAP_DRIVER_GET_CAPS = (WM_CAP_START + 14);
- WM_CAP_FILE_SET_CAPTURE_FILE = (WM_CAP_START + 20);
- WM_CAP_FILE_GET_CAPTURE_FILE = (WM_CAP_START + 21);
- WM_CAP_FILE_ALLOCATE = (WM_CAP_START + 22);
- WM_CAP_FILE_SAVEAS = (WM_CAP_START + 23);
- WM_CAP_FILE_SET_INFOCHUNK = (WM_CAP_START + 24);
- WM_CAP_FILE_SAVEDIB = (WM_CAP_START + 25);
- WM_CAP_EDIT_COPY = (WM_CAP_START + 30);
- WM_CAP_SET_AUDIOFORMAT = (WM_CAP_START + 35);
- WM_CAP_GET_AUDIOFORMAT = (WM_CAP_START + 36);
- WM_CAP_DLG_VIDEOFORMAT = (WM_CAP_START + 41);
- WM_CAP_DLG_VIDEOSOURCE = (WM_CAP_START + 42);
- WM_CAP_DLG_VIDEODISPLAY = (WM_CAP_START + 43);
- WM_CAP_GET_VIDEOFORMAT = (WM_CAP_START + 44);
- WM_CAP_SET_VIDEOFORMAT = (WM_CAP_START + 45);
- WM_CAP_DLG_VIDEOCOMPRESSION = (WM_CAP_START + 46);
- WM_CAP_SET_PREVIEW = (WM_CAP_START + 50);
- WM_CAP_SET_OVERLAY = (WM_CAP_START + 51);
- WM_CAP_SET_PREVIEWRATE = (WM_CAP_START + 52);
- WM_CAP_SET_SCALE = (WM_CAP_START + 53);
- WM_CAP_GET_STATUS = (WM_CAP_START + 54);
- WM_CAP_SET_SCROLL = (WM_CAP_START + 55);
- WM_CAP_GRAB_FRAME = (WM_CAP_START + 60);
- WM_CAP_GRAB_FRAME_NOSTOP = (WM_CAP_START + 61);
- WM_CAP_SEQUENCE = (WM_CAP_START + 62);
- WM_CAP_SEQUENCE_NOFILE = (WM_CAP_START + 63);
- WM_CAP_SET_SEQUENCE_SETUP = (WM_CAP_START + 64);
- WM_CAP_GET_SEQUENCE_SETUP = (WM_CAP_START + 65);
- WM_CAP_SET_MCI_DEVICE = (WM_CAP_START + 66);
- WM_CAP_GET_MCI_DEVICE = (WM_CAP_START + 67);
- WM_CAP_STOP = (WM_CAP_START + 68);
- WM_CAP_ABORT = (WM_CAP_START + 69);
- WM_CAP_SINGLE_FRAME_OPEN = (WM_CAP_START + 70);
- WM_CAP_SINGLE_FRAME_CLOSE = (WM_CAP_START + 71);
- WM_CAP_SINGLE_FRAME = (WM_CAP_START + 72);
- WM_CAP_PAL_OPEN = (WM_CAP_START + 80);
- WM_CAP_PAL_SAVE = (WM_CAP_START + 81);
- WM_CAP_PAL_PASTE = (WM_CAP_START + 82);
- WM_CAP_PAL_AUTOCREATE = (WM_CAP_START + 83);
- WM_CAP_PAL_MANUALCREATE = (WM_CAP_START + 84);
- function capCreateCaptureWindowA(lpszWindowName: PCHAR;
- dwStyle: longint;
- x: integer;
- y: integer;
- nWidth: integer;
- nHeight: integer;
- ParentWin: HWND;
- nId: integer): HWND; stdcall; external 'avicap32.dll';
- procedure Register;
- begin
- RegisterComponents('FstiCtl', [TVideoCapture]);
- end;
- { TVideoCapture }
- constructor TVideoCapture.Create(AOwner: TComponent);
- begin
- inherited Create(AOwner);
- CapturingAVI := false;
- Color := clBlack;
- BevelOuter := bvNone;
- Width := 320;
- Height := 240;
- hWndC := 0;
- end;
- destructor TVideoCapture.Destroy;
- begin
- if CapturingAVI then StopAvi;
- if hWndC <> 0 then CloseVideo;
- hWndC := 0;
- inherited;
- end;
- procedure TVideoCapture.OpenVideo(handle: THandle);
- begin
- hWndC := capCreateCaptureWindowA('Video Capture Window',
- WS_CHILD or WS_VISIBLE,
- Left,
- Top,
- Width,
- Height,
- Handle,
- 0);
- if hWndC <> 0 then
- SendMessage(hWndC, WM_CAP_DRIVER_CONNECT, 0, 0);
- end;
- procedure TVideoCapture.CloseVideo;
- begin
- if hWndC <> 0 then begin
- SendMessage(hWndC, WM_CAP_DRIVER_DISCONNECT, 0, 0);
- SendMessage(hWndC, WM_CLOSE, 0, 0);
- hWndC := 0;
- end;
- end;
- procedure TVideoCapture.GrabFrame;
- begin
- if hWndC <> 0 then
- SendMessage(hWndC, WM_CAP_GRAB_FRAME, 0, 0);
- end;
- procedure TVideoCapture.SaveBitMap(filename: TFileName);
- begin
- SendMessage(hWndC, WM_CAP_FILE_SAVEDIB, 0, longint(pchar(FileName)));
- end;
- function TVideoCapture.StartAvi(filename: TFileName): Boolean;
- begin
- if hWndC <> 0 then begin
- CapturingAVI := true;
- SendMessage(hWndC,
- WM_CAP_FILE_SET_CAPTURE_FILE,
- 0,
- Longint(pchar(FileName)));
- SendMessage(hWndC, WM_CAP_SEQUENCE, 0, 0);
- end;
- end;
- procedure TVideoCapture.StopAvi;
- begin
- if hWndC <> 0 then begin
- SendMessage(hWndC, WM_CAP_STOP, 0, 0);
- CapturingAVI := false;
- end;
- end;
- procedure TVideoCapture.SaveJpeg(filename: TFileName;
- compressibility: Integer);
- var
- bmp: TBitMap;
- jpg: TJpegimage;
- begin
- try
- SaveBitMap('tmp.bmp');
- bmp := TBitmap.Create;
- jpg := TJpegImage.Create;
- bmp.LoadFromFile('tmp.bmp');
- jpg.Assign(bmp);
- jpg.CompressionQuality := compressibility;
- jpg.Compress;
- jpg.SaveToFile(filename);
- DeleteFile('tmp.bmp');
- except
- end;
- bmp.free;
- jpg.free;
- end;
- procedure TVideoCapture.SetVideoFormat;
- begin
- SendMessage(hWndC, WM_CAP_DLG_VIDEOFORMAT, 0, 0);
- end;
- procedure TVideoCapture.SetSource;
- begin
- SendMessage(hWndC, WM_CAP_DLG_VIDEOSOURCE, 0, 0);
- end;
- procedure TVideoCapture.StartVideo;
- begin
- SendMessage(hWndC, WM_CAP_SET_PREVIEW, -1, 0);
- SendMessage(hWndC, WM_CAP_SET_PREVIEWRATE, 100, 0);
- SendMessage(hWndC, WM_CAP_SET_SCALE, -1, 0);
- end;
- procedure TVideoCapture.StopVideo;
- begin
- SendMessage(hWndC, WM_CAP_SET_PREVIEW, 0, 0);
- end;
- procedure TVideoCapture.WMSize(var Message: TWMSize);
- begin
- SetWindowPos(hWndC, HWND_BOTTOM, 0, 0, Width, Height, SWP_NOMOVE or SWP_NOACTIVATE);
- end;
- procedure TVideoCapture.SetStretch(TrueorFalse: Boolean);
- begin
- end;
- procedure TVideoCapture.SetCompression;
- begin
- SendMessage(hWndC, WM_CAP_DLG_VIDEOCOMPRESSION, 0, 0)
- end;
- procedure TVideoCapture.SavetoJpegStream(var JpegStream: TMemoryStream; compressibility: Integer);
- var
- bmp: TBitMap;
- jpg: TJpegimage;
- begin
- try
- SaveBitMap('tmp.bmp');
- bmp := TBitmap.Create;
- jpg := TJpegImage.Create;
- bmp.LoadFromFile('tmp.bmp');
- jpg.Assign(bmp);
- jpg.CompressionQuality := compressibility;
- jpg.Compress;
- jpg.SaveToStream(JpegStream);
- DeleteFile('tmp.bmp');
- except
- end;
- bmp.free;
- jpg.free;
- end;
- end.
TVideoCapture类的源码,继承TCustomPanel,用于视频捕获(用到了SendMessage和SetWindowPos等API)good的更多相关文章
- 25 BasicUsageEnvironment0基本使用环境基类——Live555源码阅读(三)UsageEnvironment
25 BasicUsageEnvironment0基本使用环境基类——Live555源码阅读(三)UsageEnvironment 25 BasicUsageEnvironment0基本使用环境基类— ...
- String类——StringBuilder类的源码及内存分析(java)
相同:底层均采用字符数组value来保存字符串 区别:String类的value数组有final 修饰,指向不可改,同时private 未提供修改value数组的方法.StringBuilder类的v ...
- 24 UsageEnvironment使用环境抽象基类——Live555源码阅读(三)UsageEnvironment
24 UsageEnvironment使用环境抽象基类——Live555源码阅读(三)UsageEnvironment 24 UsageEnvironment使用环境抽象基类——Live555源码阅读 ...
- String类的源码分析
之前面试的时候被问到有没有看过String类的源码,楼主当时就慌了,回来赶紧补一课. 1.构造器(构造方法) String类提供了很多不同的构造器,分别对应了不同的字符串初始化方法,此处从源码中摘录如 ...
- 分享自己用的php分页类实例源码
分享一个我自己用着的php分页类实例源码,供大家参考,具体内容如下: <?php /** file: page.class.php 完美分页类 Page */ class Page { priv ...
- 线程池 ThreadPoolExecutor 类的源码解析
线程池 ThreadPoolExecutor 类的源码解析: 1:数据结构的分析: private final BlockingQueue<Runnable> workQueue; // ...
- 【高并发】通过ThreadPoolExecutor类的源码深度解析线程池执行任务的核心流程
核心逻辑概述 ThreadPoolExecutor是Java线程池中最核心的类之一,它能够保证线程池按照正常的业务逻辑执行任务,并通过原子方式更新线程池每个阶段的状态. ThreadPoolExecu ...
- 12 哈希表相关类——Live555源码阅读(一)基本组件类
12 哈希表相关类--Live555源码阅读(一)基本组件类 这是Live555源码阅读的第一部分,包括了时间类,延时队列类,处理程序描述类,哈希表类这四个大类. 本文由乌合之众 lym瞎编,欢迎转载 ...
- commoncrawl 源码库是用于 Hadoop 的自定义 InputFormat 配送实现
commoncrawl 源码库是用于 Hadoop 的自定义 InputFormat 配送实现. Common Crawl 提供一个示例程序 BasicArcFileReaderSample.java ...
随机推荐
- php实现求扑克牌顺子(*****)(AC)(分类:把问题分小,利于排错)
php实现求扑克牌顺子(*****)(AC)(分类:把问题分小,利于排错) 一.总结 分类(那就可以把问题分小而逐步完成每个板块,这样是很简单的) 分类还有助于查错 二.php实现求扑克牌顺子 题目描 ...
- 忙里偷闲( ˇˍˇ )闲里偷学【C语言篇】——(3)输入输出函数
一.基本的输入和输出函数的用法 1.printf() //屏幕输出 用法: (1)printf("字符串\n"); (2)printf("输出控制符", 输出 ...
- 微信小程序从零开始开发步骤(二)
上一章注册完小程序,添加新建的项目,大致的准备开发已经完成,本章要分享的是要创建一个简单的页面了,创建小程序页面的具体几个步骤: 1. 在pages 中添加一个目录 选中page,右击鼠标,从硬盘打开 ...
- 避免if语句的深层次嵌套
公司做了个抢红包的限制,然后ajax请求的返回字段,要进行多层逻辑的判断,想想是真恶心,虽然都是简单逻辑,而且看别人以前写的代码,发现,哎,注释能不能写上吶,像我写代码都是细致到,哪怕初学者也能看懂这 ...
- [React] Recompose: Override Styles & Elements Types in React
When we move from CSS to defining styles inside components we lose the ability to override styles wi ...
- js 复制文本的四种方式
js 复制文本的四种方式 一.总结 一句话总结:js文本复制主流方法:document的execCommand方法 二.js 复制文本的四种方式 纯 转载复制,非原创 原地址:http://www.c ...
- leveldb学习:skiplist
leveldb中的memtable仅仅是一个封装类,它的底层实现是一个跳表. 跳表是一种基于随机数的平衡数据结构.其它的平衡数据结构还有红黑树.AVL树.但跳表的原理比它们简单非常多.跳表有点像链表, ...
- 修改NuGet packages目录路径
在*.sln文件同目录下新建配置文件nuget.config,内容为 <?xml version="1.0" encoding="utf-8"?> ...
- 【BZOJ 1031】[JSOI2007]字符加密Cipher(后缀数组模板)
[题目链接]:http://www.lydsy.com/JudgeOnline/problem.php?id=1031 [题意] [题解] 后缀数组模板题; 把整个字符串扩大一倍. 即长度乘2 然后搞 ...
- 从文件 I/O 看 Linux 的虚拟文件系统
1 引言 Linux 中允许众多不同的文件系统共存,如 ext2, ext3, vfat 等.通过使用同一套文件 I/O 系统 调用即可对 Linux 中的任意文件进行操作而无需考虑其所在的具体文件系 ...