注册 登录
编程论坛 VFP论坛

调用摄像头黑屏

hysoft88 发布于 2024-08-04 11:28, 176 次点击
1:表单的LOAD代码
Public WM_CAP_DRIVER_DISCONNECT

PUBLIC WM_CAP_SET_CALLBACK_VIDEOSTREAM
PUBLIC WM_CAP_SET_CALLBACK_ERROR
PUBLIC WM_CAP_SET_CALLBACK_STATUSA
PUBLIC WM_CAP_DRIVER_CONNECT
PUBLIC WM_CAP_SET_SCALE
PUBLIC WM_CAP_SET_PREVIEWRATE
PUBLIC WM_CAP_SET_OVERLAY
PUBLIC WM_CAP_SET_PREVIEW
PUBLIC WM_CAP_START
PUBLIC WM_USER


Public hwndc,WM_CAP_SAVEDIB,WM_CAP_FILE_SET_CAPTURE_FILEA,WM_CAP_SEQUENCE,WM_CAP_STOP
Declare Integer capCreateCaptureWindowA In "AVICAP32.DLL" String lpszWindowName ,Integer dwStyle ,;
    Integer x, Integer Y, Integer nWidth ,Integer nHeight,Integer ParentWin,Integer nId
Declare Integer SendMessage In "user32" Integer HWnd, Integer wmsg,Integer wpar1, Integer wpar2
Declare Integer SendMessage In "user32" As SendMessageA Integer HWnd, Integer wmsg,Integer wpar1,String wpar2
hwndc=0

2按钮的INIT代码:
WM_USER = 1024
WM_CAP_START = WM_USER
WM_CAP_STOP = WM_CAP_START + 68
WM_CAP_DRIVER_CONNECT = WM_CAP_START + 10
WM_CAP_DRIVER_DISCONNECT = WM_CAP_START + 11

WM_CAP_SAVEDIB = WM_CAP_START + 25
WM_CAP_GRAB_FRAME = WM_CAP_START + 60
WM_CAP_SEQUENCE = WM_CAP_START + 62
WM_CAP_FILE_SET_CAPTURE_FILEA = WM_CAP_START + 20
WM_CAP_SEQUENCE_NOFILE =WM_CAP_START+ 63
WM_CAP_SET_OVERLAY =WM_CAP_START+ 51
WM_CAP_SET_PREVIEW =WM_CAP_START+ 50
WM_CAP_SET_CALLBACK_VIDEOSTREAM = WM_CAP_START +6
WM_CAP_SET_CALLBACK_ERROR=WM_CAP_START +2
WM_CAP_SET_CALLBACK_STATUSA= WM_CAP_START +3
WM_CAP_SET_CALLBACK_FRAME= WM_CAP_START +5
WM_CAP_SET_SCALE=WM_CAP_START+ 53
WM_CAP_SET_PREVIEWRATE=WM_CAP_START+ 52

3.按钮的CLICK 代码
hWndC = capCreateCaptureWindowA('My Own Capture Window',1342177280,340,100,620,440,Thisform.HWnd ,0)



If hWndC<>0
      
    SendMessage(hWndC, WM_CAP_SET_CALLBACK_VIDEOSTREAM, 0, 0)    &&设置回调视频流
    SendMessage(hWndC, WM_CAP_SET_CALLBACK_ERROR, 0, 0)        &&设置回调错误
    SendMessage(hWndC, WM_CAP_SET_CALLBACK_STATUSA, 0, 0)    &&设置回调状态,原始值为:0,0
    SendMessage(hWndC, WM_CAP_DRIVER_CONNECT, 0, 0)        &&驱动程序连接
    SendMessage(hWndC, WM_CAP_SET_SCALE, 1, 0)            &&设置预览视频的缩放比例
    SendMessage(hWndC, WM_CAP_SET_PREVIEWRATE, 66, 0)    &&设置预览模式下图像的帧速度
    SendMessage(hWndC, WM_CAP_SET_OVERLAY, 1, 0)    &&设置覆盖
    SendMessage(hWndC, WM_CAP_SET_PREVIEW, 1, 0)    &&设置预览模式
ENDIF

&&问题:1、测试发现,这段if ...endif 必须连续的执行两次(如下),才能打开摄像头,如果不执行第二次,则弹出摄像头的选择确认窗口,选择确认后,摄像头打不开;
&&      2、如果有前、后两个摄像头,没有默认选择项(即必须在弹出的窗口中选择一个摄像头,然后确认),则执行第二次,同样打不开摄像头
&&       也就是说,一旦有摄像头选择的窗口弹出来,则后续就打不开摄像头了

If hWndC<>0
    SendMessage(hWndC, WM_CAP_SET_CALLBACK_VIDEOSTREAM, 0, 0)    &&设置回调视频流
    SendMessage(hWndC, WM_CAP_SET_CALLBACK_ERROR, 0, 0)        &&设置回调错误
    SendMessage(hWndC, WM_CAP_SET_CALLBACK_STATUSA, 0, 0)    &&设置回调状态,原始值为:0,0
    SendMessage(hWndC, WM_CAP_DRIVER_CONNECT, 0, 0)        &&驱动程序连接
    SendMessage(hWndC, WM_CAP_SET_SCALE, 1, 0)            &&设置预览视频的缩放比例
    SendMessage(hWndC, WM_CAP_SET_PREVIEWRATE, 66, 0)    &&设置预览模式下图像的帧速度
    SendMessage(hWndC, WM_CAP_SET_OVERLAY, 1, 0)    &&设置覆盖
    SendMessage(hWndC, WM_CAP_SET_PREVIEW, 1, 0)    &&设置预览模式
ENDIF



thisform.关闭镜头.Enabled= .T.
thisform.录制视频.Enabled= .T.
thisform.拍照储存.Enabled= .T.
this.Enabled= .F.

4结果
只有本站会员才能查看附件,请 登录


点录制视频时偶尔可以录,但录的同时软件会卡死,我设置了SET ESCAPE ON所以可以用ESC退出,这样录的视频还是正常的。但就是黑屏,不知哪位大佬能指导一二,多谢。
3 回复
#2
hysoft882024-08-04 11:30
对了,补充一下,我用的是WIN11系统,我另外还尝试了AVCAP.OCX,但在我的系统上怎么都注册不了

#3
iswith2024-08-04 11:50
应该是驱动没有适配win11这么新的系统吧!其实读摄像头流这块有点乱了。。。。AVICAP32.DLL是不是有点太老了,几十年前的东西了。。。。
#4
sych2024-08-05 09:08
=SendMessage(hwndc, 1024+41, 0,  0)
改一下压缩模式
1