Traditional Culture Encyclopedia - Photography and portraiture - Realization of hardware camera function of VB camera

Realization of hardware camera function of VB camera

This is not your problem. No one will answer. I asked you a question in the wrong place. This belongs to hardware programming. Of course, if you put it into software programming, few people will answer. Here is an example. Click the photo button on the camera directly. Private Sub-Form _Load ()

Dim lpszName is String * 100.

Dim lpszVer As String * 100

Create a video window

Read the list of drivers

capGetDriverDescriptionA 0,lpszName, 100,lpszVer, 100

Create a video window program

Lwndc = capcreatecapturewindowa (lpszname, WS_CAPTION or WS_THICKFRAME or WS_VISIBLE or WS_CHILD, -5, -30, Pic). Width, picture. Height, figure hwnd, 0)

Connect the capture window to the capture device.

If capDriverConnect(lwndC, 0), then

Enables or disables zooming in preview mode.

capPreviewScale lwndC,True

Send to the capture window to set the display frequency of frames in preview mode.

CapPreviewRate lwndC, 66 years old

Send to capture window to enable or disable preview mode.

capPreview lwndC,True

Adjust the size and display format of the form.

SetWindowPos lwndC, HWND_BOTTOM, 0,0,430,350, SWP _ Noumoff or SWP _ Nuo zod.

If ... it will be over.

End joint

In-module code:

Public Const WS _ BORDER = & ampH800000

Public Const WS _ CAPTION = & ampHC00000

Public Const WS _ SYSMENU = & ampH80000

Public Const WS _ CHILD = & ampH40000000

Public constws _ visible = & amph10000000

Common constant WS _ OVERLAPPED = & ampH0 & amp;

Common constant WS _ MINIMIZEBOX = & ampH20000

Common constant ws _ maximizebox = & amph10000

Common constant WS _ THICKFRAME = & ampH40000

Public const ws _ overlapped window = (ws _ overlapped or WS_CAPTION or WS_SYSMENU or WS_THICKFRAME or WS_MINIMIZEBOX or WS_MAXIMIZEBOX).

Public construction SWP _ nomove = & deuterium

Public building SWP _ Noxize = 1

Public Construction SWP _ Nuozod = & ampH4

Common constant HWND_BOTTOM = 1

Common constant HWND_TOPMOST =-1

Common constant hwnd _ nottopmost =-2

Public Const SM _ CYCAPTION = 4

Common constant SM_CXFRAME = 32

Common constant SM_CYFRAME = 33

Common constant ws _ ex _ transparent =&h20 &

Public building GWL_STYLE = (- 16)

Set a value for the form.

Declare the alias "setwindowLonga" of the function setwindowLonglib "user 32" (byval hwnd is Long, ByVal nIndex is Long, ByVal dwNewLong is long) as long.

Declare the function lStrCpy Lib "kernel32 "alias" lstrcpya "(byval lpstring1is Long, ByVal lpString2 is Long) as Long.

Declare the function lStrCpyn Lib "kernel32 "alias" lstrcpyna "(byval lpstring1is Any, ByVal lpString2 is Long and ByVal iMaxLength is Long) as Long.

Declare the Sub RtlMoveMemory library "kernel 32”(ByVal HPV dest is Long, ByVal hpvSource is Long, ByVal cbCopy is Long).

Declare the Sub hmemcpy library "kernel32" (HPV test is Any, hpvSource is Any, ByVal cbCopy is Long).

This function specifies a new position and state for the window. It can also change the position of the window in the internal window list.

Declare the function setwindowpos lib "user 32" (byval hwnd is Long, ByVal hWndInsertAfter is Long, ByVal X is Long, ByVal Y is Long, ByVal cx is Long, ByVal cy is Long, ByVal wFlags is Long) as Long.

Close the form and subform.

The function destroy windowlib "user 32" (byval hndwas long) is declared as a boolean value.

Declare the function getsystemmetrics lib "user 32" (byval index is Long) as Long.

Sets the information of the specified window in the structure.

Declare the function setwindowtextlib“user 32 "alias" SetWindowTextA”(ByVal hwnd is Long, ByVal lpString is String) as Long.

Public lwndC of "long" handle

Common constant HTCAPTION = 2

Public constwm _ nclbuttondown = & ampha1

The public declaration function ReleaseCapture Lib "user32 "() is Long.

* * * * * * * * * * * * * * * * * * * * * * * * * * * Save the front window.

Common constwm _ user =&"h400" offset address

POINTAPI type

X is the same length

as long as

End type

Call the window function of a window and send a message to that window. This function will not return until the message is processed.

Hwnd(long) is the handle of the window that receives the message, the identifier of wmsg(long) message, wparam(long) dependency message iparam(ANY) dependency message.

The alias "SendMessage a”(ByVal hwnd is Long, ByVal wMsg is Long, ByVal wParam is Integer, ByVal lParam is Long) of the function sendmessagelib" user 32 "is declared as Long.

Declare the alias "sendmessage a”(ByVal hwnd is Long, ByVal wMsg is Long, ByVal wParam is Integer, ByVal lParam is String) of the function sendmessagelib" user 32 "as Long.

Public constwm _ cap _ start = wm _ user' start address

public Const WM _ CAP _ GET _ CAPSTREAMPTR = WM _ CAP _ START+ 1 '

Callback function called when public const WM _ cap _ set _ callback _ error = WM _ cap _ start+2' program setting error occurs.

Public constwm _ cap _ set _ callback _ status = wm _ cap _ start+3' sets the callback function called when the state changes in the program.

Public constwm _ cap _ set _ callback _ yield = wm _ cap _ start+4' Sets the callback function to be called when the program gives way.

Public constwm _ cap _ set _ callback _ frame = wm _ cap _ start+5' sets the modulation function to be called when the preview frame is captured in the program.

Public constwm _ cap _ set _ callback _ videostream = wm _ cap _ start+6' Sets the callback function to be called when there is a new video buffer in the program.

Public constwm _ cap _ set _ callback _ wavestream = wm _ cap _ start+7' Sets the callback function to be called when a new audio buffer is available in the program.

Public constwm _ cap _ get _ user _ data = wm _ cap _ start+8' You can obtain long integer data by associating the data with the capture window.

Public constwm _ cap _ set _ user _ data = wm _ cap _ start+9' associate data with a capture window', and you can set a long integer data.

Public constwm _ cap _ driver _ connect = wm _ cap _ start+10' connects the capture window to the capture device.

Public constwm _ cap _ driver _ disconnect = wm _ cap _ start+11'is used to disconnect the capture driver from the capture window.

Public constwm _ cap _ driver _ get _ name = wm _ cap _ start+12' connect' to get the name of the capture device driver connected to the capture window.

Public constwm _ cap _ driver _ get _ version = wm _ cap _ start+13' to get the version number of the driver.

Public constwm _ cap _ driver _ get _ caps = wm _ cap _ start+14' to obtain the performance of the hardware that captures the window.

Capture files and cache

Public constwm _ cap _ file _ set _ capture _ file = wm _ cap _ start+20' can specify another path and file name. This message specifies the file name, but does not create the file, nor does it open the file or request file space.

Public constwm _ cap _ file _ get _ capture _ file = wm _ cap _ start+21'to get the current capture file.

Public constwm _ cap _ file _ allocate = wm _ cap _ start+22' pre-allocates space for the captured file, thus reducing the number of lost frames.

Public constwm _ cap _ file _ saveas = wm _ cap _ start+23' Save the captured file as a file specified by other users. This message will not change the name and content of the captured file.

Because the capture file retains its original file name, you must specify a new file name to save it.

Public constwm _ cap _ file _ set _ infochunk = wm _ cap _ start+24' You can insert information blocks such as text or custom data in avi files. This message can also be used to clear information blocks in avi files.

Public const WM _ CAP _ FILE _ SAVE DIB = WM _ CAP _ START+25' save that image copied from the frame buff as a device independent bit bank (DIB), and the application can also use these two single frame capture messages to edit the frame sequence.

Or create a slow shooting sequence.

Public constwm _ cap _ edit _ copy = wm _ cap _ start+30' After capturing the image, copy the image in the cache to the clipboard.

Public constwm _ cap _ set _ audioformat = wm _ cap _ start+35' Set the audio format. A pointer to a WAVEFORMAT, waveformatexor PCMWAVEOFMAT structure is passed in when setting.

Public constwm _ cap _ get _ audioformat = wm _ cap _ start+36' gets the format of audio data and the size of the format structure. The default audio format is mono, 8-bit and 1 1kHZ PCM.

Public constwm _ cap _ DLG _ videoformat = wm _ cap _ start+41'Select the size and image depth of the digitized video frame and the compression method of the collected video data.

Public constwm _ cap _ DLG _ videosource = wm _ cap _ start+42' video dialog box, which is used to enumerate the signal types of the acquisition card connected to the video source, and

Controls changes in color, contrast and saturation. If the graphics card driver is skilled, you can use this dialog.

The public constwm _ cap _ DLG _ videodisplay = wm _ cap _ start+43' video display dialog box controls the video display on the display during video capture. It has no effect on the captured data, but it will affect the expression of the counting signal.

Public constwm _ cap _ get _ videoformat = wm _ cap _ start+44' gives the structure of obtaining the video format and the size of the structure.

Public constwm _ cap _ set _ videoformat = wm _ cap _ start+45' is used to set the video format.

Public const WM _ Cap _ DLG _ Video Compression = WM _ Cap _ Start+46' Video Compression Dialog Box

Public constwm _ cap _ set _ preview = wm _ cap _ start+50' is sent to the capture window to enable or disable the preview mode.

Public constwm _ cap _ set _ overlay = wm _ cap _ start+51'puts the window in overlay mode. Enabling override mode also automatically disables preview mode.

Public constwm _ cap _ set _ previewrate = wm _ cap _ start+52' is sent to the capture window to set the display frequency of frames in preview mode.

Public constwm _ cap _ set _ scale = wm _ cap _ start+53' enables or disables zooming in preview mode.

Public constwm _ cap _ get _ status = wm _ cap _ start+54' gets the current state of the capture window.

Public constwm _ cap _ set _ scroll = wm _ cap _ start+55' If it is in preview mode or overlay mode, it can also be sent to the window through this message.

Sets the position of the video frame scroll bar in the user area of the window.

Define the response information at the end.

Common constant WM _ cap _ set _ callback _ capcontrol = WM _ cap _ start+85.

Common constant WM _ cap _ end = WM _ cap _ set _ callback _ capcontrol.

//Import two functions under the avicap32.dll connection library.

Declare the function capcreatecapturewindowalib "avicap32.dll" (_

ByVal lpszWindowName as a string, _

ByVal dwStyle As Long,_

ByVal X is Long, ByVal Y is Long, ByVal nWidth is Long, ByVal nHeight is an integer, _

ByVal hWndParent is as long as ByVal nID.

Declare the function capgetdriverdescriptionalib "avicap32.dll" (_

ByVal wDriver is an integer, _

ByVal lpszName as a string, _

ByVal cbName As Long,_

ByVal lpszVer as a string, _

ByVal is as long as Boolean.

The function capDriverConnect(ByVal lwnd is Long, ByVal i is Integer) is a boolean value.

Connect the capture window to the capture device.

capDriverConnect = SendMessage(lwnd,WM_CAP_DRIVER_CONNECT,I,0)

End function

The function capdriver disconnect (byval lwnd as long) is a boolean value.

Used to disconnect the capture drive from the capture window.

capDriverDisconnect = SendMessage(lwnd,WM_CAP_DRIVER_DISCONNECT,0,0)

End function

The function capdrivegetname (byvallwnd is Long, ByVal szName is Long, ByVal wSize is Integer) is a boolean value.

Get the driver name

capDriverGetName = SendMessage(lwnd,YOURCONSTANTMESSAGE,wSize,szName)

End function

The function capdrivegetcaps (byvallwnd is Long, ByVal s is Long, ByVal wSize is Integer) is a boolean value.

To obtain the performance of the hardware that captures the window.

capDriverGetCaps = SendMessage(lwnd,WM_CAP_DRIVER_GET_CAPS,wSize,s)

End function

The function capPreview(ByVal lwnd is Long, ByVal f is Boolean) is Boolean.

Send to capture window to enable or disable preview mode.

capPreview = SendMessage(lwnd,WM_CAP_SET_PREVIEW,f,0)

End function

The function capppreviewwrap (byvallwnd is Long, ByVal wMS is Integer) is a boolean value.

Send to the capture window to set the display frequency of frames in preview mode.

capPreviewRate = SendMessage(lwnd,WM_CAP_SET_PREVIEWRATE,wMS,0)

End function

The function capPreviewScale(ByVal lwnd is Long, ByVal f is Boolean) is Boolean.

Enables or disables zooming in preview mode.

capPreviewScale = SendMessage(lwnd,WM_CAP_SET_SCALE,f,0)

Although End Function says that there are certain standards for camera production, we can't guarantee that all cameras will follow this standard, especially parallel imports and some counterfeit products with miscellaneous brands. If your camera is a famous brand, there is no problem.