Home > Software engineering >  In VB6 cut using ordinary USB camera, how to take pictures?
In VB6 cut using ordinary USB camera, how to take pictures?

Time:09-24

I use VB6, add a PictureBox or Image in the form, used to represent the camera shows the shooting area, now added a button, photo let photographed pictures showed in the PictureBox box, I looked on the net, once the filming starts, feeling is called resource problem, did Daniel, please grant instruction!

CodePudding user response:

The request and help!

CodePudding user response:

Don't know you how to use,,,,,,,

CodePudding user response:

I use the Internet a program, as follows:
. Bas part code
 Private Declare Function capCreateCaptureWindow Lib "avicap32. DLL" _ 
Alias "capCreateCaptureWindowA" (_
ByVal lpszWindowName As String, _
ByVal dwStyle As Long, _
ByVal x As Long, _
ByVal y As Long, _
ByVal nWidth As Long, _
ByVal nHeight As Long, _
ByVal hWndParent As Long, _
ByVal nID As Long As Long)

Private Const WS_CHILD=& amp; H40000000
Private Const WS_VISIBLE=& amp; H10000000
Private Const WM_USER=& amp; H400
Private Const WM_CAP_START=& amp; H400
Private Const WM_CAP_EDIT_COPY=(WM_CAP_START + 30)
Private Const WM_CAP_DRIVER_CONNECT=(WM_CAP_START + 10)
Private Const WM_CAP_SET_PREVIEWRATE=(WM_CAP_START + 52)
Private Const WM_CAP_SET_OVERLAY=(WM_CAP_START + 51)
Private Const WM_CAP_SET_PREVIEW=(WM_CAP_START + 50)
Private Const WM_CAP_DRIVER_DISCONNECT=(WM_CAP_START + 11)

Private Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" (_
ByVal HWND As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
LParam As Long As Any)

Private Preview_Handle As Long

The Public Function CreateCaptureWindow (_
HWndParent As Long, _
Optional x As Long=0, _
Optional As Long=0, y _
Optional nWidth As Long=440, _
Optional nHeight As Long=440, _
Optional nCameraID As Long As Long=0)

Preview_Handle=capCreateCaptureWindow (" Video, "_
WS_CHILD + WS_VISIBLE, x, y, _
NWidth, nHeight, hWndParent, 1)

SendMessage Preview_Handle WM_CAP_DRIVER_CONNECT, nCameraID, 0
SendMessage Preview_Handle WM_CAP_SET_PREVIEWRATE, 30, 0
SendMessage Preview_Handle WM_CAP_SET_OVERLAY, 1, 0
SendMessage Preview_Handle WM_CAP_SET_PREVIEW, 1, 0

CreateCaptureWindow=Preview_Handle
End the Function

The Public Function CapturePicture (nCaptureHandle As Long) As StdPicture
The Clipboard. The Clear
SendMessage nCaptureHandle WM_CAP_EDIT_COPY, 0, 0
The Set CapturePicture=Clipboard. GetData
End the Function


Public Sub Disconnect (nCaptureHandle As Long, _
Optional nCameraID=0)

SendMessage nCaptureHandle WM_CAP_DRIVER_DISCONNECT, _
NCameraID, 0
End Sub

Put a form, a button, a picturebox control, form part of the code:
Dim Video_Handle As Long

Private Sub Command1_Click ()
Dim x As StdPicture
The Set x=CapturePicture (Video_Handle)
SavePicture x, "c: \ a1. BMP"
PicCapture. Visible=False
NowPic. Visible=True
NowPic. Picture=LoadPicture (" c: \ a1. BMP ")
Image1. Picture=LoadPicture (" c: \ a1. BMP ")
End Sub

Private Sub Form_Load ()
Video_Handle=CreateCaptureWindow (PicCapture HWND)
NowPic. Visible=False
End Sub

Private Sub Form_Unload (Cancel As Integer)
Disconnect Video_Handle
End Sub

Perform to the two sentence error:
The Set x=CapturePicture (Video_Handle)
SavePicture x, "c: \ a1. BMP"
Tip error is:
Runtime error "521" can 't open clipboard
I don't know what reason?

CodePudding user response:

My mistake is "380" invalid attribute value

CodePudding user response:

for the roof, I seriously doubt that you are will play in Chinese foreigner, because I saw three times, didn't see what you're talking about, although the word all know...

Looked at 3/f, finally let me understand:
Originally you because there is an error in this code

Ok, digress, Chinese grammar problem, I can't help you, but the VB problem can still help to point:

Your mistake is "runtime error" 521 "can 't open clipboard", speak is very understand, unable to open clipboard.

From CapturePicture () function implementation, the need to cut the figure on the clipboard to get it back again, to get a stdPicture object, in order to save.

The Public Function CapturePicture (nCaptureHandle As Long) As StdPicture
The Clipboard. The Clear
SendMessage nCaptureHandle WM_CAP_EDIT_COPY, 0, 0
The Set CapturePicture=Clipboard. GetData
End the Function

As to why this code you can't open the clipboard, you have to be CapturePicture with () inside, make clear the specific error is where one line.

If the Clipboard. The Clear, that it is possible that other programs are using, can try to Sleep with a belt loop to call this a (100), no error that is success.

In addition, this method is not good, because you do not need to use to the clipboard, WM_CAP_EDIT_COPY news is convenient in other places (such as QQ chat window) paste images and use, are you here to save to file and display, the use of WM_CAP_FILE_SAVEDIB news is the most suitable.

Here to give you a package:

 Function capFileSaveDIB (ByVal hCapWnd As Long, ByVal As FilePath String) As Boolean 
CapFileSaveDIB=SendMessageAsString (hCapWnd WM_CAP_FILE_SAVEDIB, 0 & amp; FilePath)
End the Function

'call:
If not capFileSaveDIB (Video_Handle, "C: \ a1. BMP") then
Msgbox "save failed!"
End the if

CodePudding user response:

When access to video and access to other forms of API is not the same, before I've tested with API not intercept of the figure of the film, never try again later,
null
  • Related