天天看點

delphi dxCameraControl控件(拍照)

拍照示範

DevExpressVCL 元件之一

TdxCameraControl Object

Hierarchy   Properties   Methods   Events

一個攝像頭控件

Unit dxCameraControl

Syntax

TdxCameraControl = class(TdxCustomCameraControl)

Descrition

該控件允許您捕捉視訊或圖像從内置/連接配接的網絡攝像頭或裝置、前後攝像頭。也可以通路指定的攝像頭,并可以預覽;

該控件實作與錄影機相關聯的基本功能。它使用允許您執行以下操作:

可以指定圖像/視訊捕獲的錄影機,并擷取其名稱:(DeviceIndex和DeviceName)。

可以控制錄影機的視訊:活動、暫停、播放和停止 (Active, Pause, Play, Stop).

會列出來支援的錄影機分辨率,使用者可以選擇一個分辨率或者分辨率索引用于輸出:(Resolutions 和ResolutionIndex).

可以縮放渲染圖像(FitMode)。

捕獲截屏目前渲染的圖像并通路它:(Capture 和 CapturedBitmap).

擷取控件的目前狀态,以及狀态更改事件(state和OnStateChanged)。

啟用設定按鈕,提供使用者對彈出菜單的通路,您也可以以程式設計方式調用該菜單(ShowSettingsButton和ShowSettingsToolbar)。

TdxCameraControl Properties(屬性)

TdxCameraControl   Legend

Derived from TdxCustomCameraControl      

Active      激活控件

BorderStyle      控件的邊框風格

CapturedBitmap      捕捉的圖像

DeviceIndex      攝像頭裝置索引

DeviceName      目前攝像頭的名字

FitMode      填充模式

ResolutionCount      傳回目前通路的錄影機支援的分辨率數目

ResolutionIndex      傳回目前分辨率的索引

Resolutions      分辨率

State      控件目前的狀态

ShowSettingsButton  是否顯示設定按鈕

TdxCameraControl Methods(方法)

Capture      從目前攝像頭捕獲一張圖檔

Pause      使目前攝像頭處于暫停狀态

Play         使目前攝像頭處于預覽輸出狀态

ShowSettingsToolbar      調用設定彈出菜單。

Stop  停止渲染從攝像頭獲得的輸出幀,使攝像頭處于不激活的狀态。

TdxCustomCameraControl Events(事件)

TdxCustomCameraControl   Legend

In TdxCustomCameraControl      

OnStateChanged  控件狀态發生變化時 

TdxCustomCameraControl.DeviceIndex

TdxCustomCameraControl

通過索引指定目前控件的攝像頭處于激活;

property DeviceIndex: Integer;

Description

控件是通過在裝置管理器中注冊的錄影機清單(也稱為網絡錄影機或成像裝置)中的索引來識别的。預設情況下,控件被設定為通路清單中的第一個相機。如果注冊了多個錄影機,可以使用DeviceIndex屬性選擇所需的錄影機。

終端使用者可以使用控件的設定彈出菜單中的裝置子菜單在相機之間切換。

TdxCustomCameraControl.State

Indicates the camera control's current state.Syntax

type  TdxCameraControlState = (ccsInactive, ccsInitializing, ccsRunning, ccsPaused, ccsNoDevice, ccsDeviceIsBusy);property State: TdxCameraControlState;

Values include:

ValueDescription

ccsInactive錄影機控制處于非活動狀态。該狀态對應sdxCameraInactive。除此之外,所有其他狀态都與錄影機控制有關。

ccsInitializing錄影機控件正在初始化以捕獲或呈現錄影機輸出。此狀态對應于sdxCameraInitializing。

ccsRunning控件在其表面呈現錄影機的輸出。(預覽) 

ccsPaused攝像頭處于暫停狀态

ccsNoDevice相機控件無法找到所選相機或目前已關閉。此狀态對應sdxcameranotdetection。

ccsDeviceIsBusy裝置處于鎖定狀态。    

這是個隻讀屬性。

Active:True

DeviceIndex:裝置号,預設為0

其他方法

procedure Capture; //捕獲

procedure Pause; //暫停

procedure Play; //播放

procedure Stop; //停止

property State: TdxCameraControlState read FState; //裝置狀态

設計界面

delphi dxCameraControl控件(拍照)

代碼

複制代碼

//拍照并在cxImage中顯示

procedure TForm1.Button1Click(Sender: TObject);

begin

  dxCameraControl1.Capture;

  cxImage1.Picture.Assign(dxCameraControl1.CapturedBitmap);

end;

//儲存圖檔

procedure TForm1.Button3Click(Sender: TObject);

  if SavePictureDialog1.Execute then

  begin

    cxImage1.Picture.SaveToFile(SavePictureDialog1.FileName);

  end;

delphi dxCameraControl控件(拍照)