Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to write and send a code to turn on the camera

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article is about how to write and send a piece of code to turn on the camera. The editor thinks it is very practical, so I share it with you. I hope you can learn something after reading this article. Let's take a look at it with the editor.

/ /-

# pragma hdrstop

# include "Unit1.h"

# include "vfw.h"

/ /-

# pragma package (smart_init)

# pragma resource "* .dfm"

TForm1 * Form1

HWND hWndC

CAPDRIVERCAPS CapDrvCaps

CAPSTATUS CapStatus

/ /-

_ _ fastcall TForm1::TForm1 (TComponent* Owner)

: TForm (Owner)

{

}

/ /-

Void _ _ fastcall TForm1::FormShow (TObject * Sender)

{

Char szDeviceName [80]

Char szDeviceVersion [80]

For (int wIndex = 0; wIndex)

< 10; wIndex++) { if (capGetDriverDescription (wIndex, szDeviceName, sizeof (szDeviceName), szDeviceVersion, sizeof (szDeviceVersion))) { ComboBox1->

Items- > Add (szDeviceName)

}

}

If (ComboBox1- > Items- > Count > 0)

ComboBox1- > ItemIndex=0

Else

{

ShowMessage ("No video software found")

Close ()

}

Button1Click (NULL)

}

/ /-

Void _ _ fastcall TForm1::Button1Click (TObject * Sender)

{

HWndC = capCreateCaptureWindow (

(LPSTR) "My Capture Window", / / window name if pop-up

WS_CHILD | WS_VISIBLE, / / window style

0, 0, 160, 120, / / window position and dimensions

(HWND) Panel2- > Handle,// (HWND) Application- > Handle,// (HWND) hwndParent

ComboBox1- > ItemIndex+1); / / (int) nID / * child ID * /)

/ / connect the device:

CapDriverConnect (hWndC,0)

CapPreviewRate (hWndC, 50); / / rate, in milliseconds

CapPreview (hWndC, TRUE); / / starts preview

/ / obtain the performance related to video driver

CapDriverGetCaps (hWndC, & CapDrvCaps, sizeof (CAPDRIVERCAPS))

/ / get the status of the capture window

CapGetStatus (hWndC, & CapStatus, sizeof (CAPSTATUS))

SetWindowPos (hWndC, NULL

0

0

CapStatus.uiImageWidth

CapStatus.uiImageHeight, SWP_NOZORDER | SWP_NOMOVE)

}

/ /-

Void _ fastcall TForm1::FormClose (TObject * Sender, TCloseAction & Action)

{

If (hWndC)

{

CapPreview (hWndC, FALSE); / / starts preview

CapDriverDisconnect (hWndC)

}

}

/ /-

Void _ _ fastcall TForm1::Button2Click (TObject * Sender)

{

/ / Video format dialog box.

If (CapDrvCaps.fHasDlgVideoFormat)

{

CapDlgVideoFormat (hWndC)

/ / Are there new image dimensions?

CapGetStatus (hWndC, & CapStatus, sizeof (CAPSTATUS))

SetWindowPos (hWndC, NULL

0

0

CapStatus.uiImageWidth

CapStatus.uiImageHeight, SWP_NOZORDER | SWP_NOMOVE)

}

}

/ /-

Void _ _ fastcall TForm1::Button3Click (TObject * Sender)

{

/ / Video source dialog box.

If (CapDrvCaps.fHasDlgVideoSource)

CapDlgVideoSource (hWndC)

}

/ /-

Void _ _ fastcall TForm1::Button4Click (TObject * Sender)

{

/ / set relevant parameters

CAPTUREPARMS CaptureParms

Float FramesPerSec = 30.0

CapCaptureGetSetup (hWndC, & CaptureParms, sizeof (CAPTUREPARMS))

CaptureParms.dwRequestMicroSecPerFrame = (DWORD) (1.0e6 /

FramesPerSec)

CapCaptureSetSetup (hWndC, & CaptureParms, sizeof (CAPTUREPARMS))

}

/ /-

Void _ _ fastcall TForm1::Button5Click (TObject * Sender)

{

/ / set the scale when previewing

CapPreviewScale (hWndC, 1)

/ / sets the frame frequency when previewing

CapPreviewRate (hWndC,66)

/ / if you want to capture a video stream, use the function to specify that no file is generated. Otherwise, the AVI file will be generated automatically

CapCaptureSequenceNoFile (hWndC)

/ / specify whether to use overlay mode, using 1, otherwise 0

CapOverlay (hWndC, 1)

/ / Video display dialog box.

If (CapDrvCaps.fHasDlgVideoDisplay)

CapDlgVideoDisplay (hWndC)

}

/ /-

Void _ _ fastcall TForm1::Button6Click (TObject * Sender)

{

If (SaveDialog2- > Execute ())

CapFileSaveDIB (hWndC, (SaveDialog2- > FileName+ ".bmp") .c_str ()); / / intercept the current frame

}

/ /-

Void _ _ fastcall TForm1::Button7Click (TObject * Sender)

{

If (Button7- > Caption = = "start capture")

{

If (SaveDialog1- > Execute ())

{

/ / Set up the capture operation.

CapCaptureSequence (hWndC)

/ / Capture.

CapFileSaveAs (hWndC, (SaveDialog1- > FileName+ ".avi") .c_str (); / / Video

}

Button7- > Caption= stop capture

}

Else

{

Button7- > Caption= "start capture"

CapCaptureStop (hWndC)

}

}

/ /-

The above is how to write and send a piece of code to turn on the camera. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report