二維碼產生與掃瞄
# PinToo之二維碼產生與一維二維碼掃瞄
# 1. 說明
該功能可用於掃瞄識別條形碼與二維碼,以及根據內容產生對應的二維碼。通過PinToo智慧控制平臺,實現識別設備條形碼的功能。可設定該功能進行連續掃瞄,識別振動提示音,識別成功提示音,打開閃光燈,識別圖片中的條形碼資訊。並且可根據文字內容產生二維碼。在使用以下功能之前,請先確認是否有給予PinToo相應的許可權。
# 2. 設計明細
開啟PinToo設計器,分別加入下插圖之控制元件。或者點選左上角的[打開模板Lib檔案]
,選擇模板檔案來打開對應模板。
①:TfxSwitch元件,控制元件名稱為fxSwitchVoice
。
②:TfxSwitch元件,控制元件名稱為fxSwitchViberate
。
③:TfxSwitch元件,控制元件名稱為fxSwitchScan
。
④:TfxSwitch元件,控制元件名稱為fxSwitchFlash
。
⑤:TfxSwitch元件,控制元件名稱為fxSwitchPhoto
。
⑥:TfxSwitch元件,控制元件名稱為fxSwitchResult
。
⑦:TfxSuperButton元件,控制元件名稱為fxSuperButtonScan
。
⑧:TfxBarCodeScanner元件,控制元件名稱為fxBarCodeScanner
。
⑨:TfxSuperButton元件,控制元件名稱為fxSuperButtonCode
。
⑩:TfxMemo元件,控制元件名稱為fxMemo1
。
(11):TfxQRCode元件,控制元件名稱為fxQRCode1
。
fxRunFrame屬性設定
Height
:設定頁面高度=800
。Width
:設定頁面寬度=400
。
①fxSwitchVoice屬性設定
Name
:設定控制元件名稱=fxSwitchVoice
。
②fxSwitchViberate屬性設定
Name
:設定控制元件名稱=fxSwitchViberate
。
③fxSwitchScan屬性設定
Name
:設定控制元件名稱=fxSwitchScan
。
④fxSwitchFlash屬性設定
Name
:設定控制元件名稱=fxSwitchFlash
。
⑤fxSwitchPhoto屬性設定
Name
:設定控制元件名稱=fxSwitchPhoto
。
⑥fxSwitchResult屬性設定
Name
:設定控制元件名稱=fxSwitchResult
。
⑦fxSuperButtonScan屬性設定
Height
:設定控制元件高度=95
。Width
:設定控制元件寬度=100
。ButtonType
:設定按鈕型別,設定為TfxSvgButton
。Name
:設定控制元件名稱=fxSuperButtonScan
。ButtonType.SvgData
:設定SVG數據,其數據內容如下。
<path d="M27.2766056060791,3 L8.34043598175049,3 C7.07802438735962,3 5.81561374664307,4.26241159439087 5.81561374664307,5.52482318878174 L5.81561374664307,23.1985816955566 C5.81561374664307,24.4609928131104 7.07802534103394,25.7234039306641 8.34043598175049,25.7234039306641 C9.6028470993042,25.7234039306641 10.8652591705322,24.4609928131104 10.8652591705322,23.1985816955566 L10.8652591705322,8.68085098266602 L26.6453990936279,8.68085098266602 C27.9078121185303,8.68085098266602 29.1702270507813,7.41843891143799 29.1702270507813,6.15602779388428 C29.1702270507813,4.89361715316772 28.5390148162842,3 27.2766056060791,3 Z M91.0283660888672,3 L73.3546142578125,3 C72.0922088623047,3 70.8297882080078,4.26241159439087 70.8297882080078,5.52482318878174 C70.8297882080078,6.78723430633545 72.0922088623047,8.04964542388916 73.3546142578125,8.04964542388916 L89.1347503662109,8.04964542388916 L89.1347503662109,23.8297863006592 C89.1347503662109,25.0921993255615 90.3971710205078,26.3546085357666 91.6595764160156,26.3546085357666 C92.9219818115234,26.3546085357666 94.1843872070313,25.0921955108643 94.1843872070313,23.8297843933105 L94.1843872070313,5.52482318878174 C93.5531768798828,4.26241159439087 92.290771484375,3 91.0283660888672,3 Z M91.0283660888672,68.645393371582 C89.7659606933594,68.645393371582 88.5035552978516,69.9078140258789 88.5035552978516,71.1702194213867 L88.5035552978516,86.9503631591797 L72.7234191894531,86.9503631591797 C71.4609985351563,86.9503631591797 70.1985931396484,88.2127685546875 70.1985931396484,89.4751815795898 C70.1985931396484,90.7375946044922 71.4609985351563,92 72.7234191894531,92 L90.3971710205078,92 C91.6595764160156,92 92.9219818115234,90.7375946044922 92.9219818115234,89.4751815795898 L92.9219818115234,71.8014144897461 C93.5532073974609,69.9077987670898 92.290771484375,68.645393371582 91.0283660888672,68.645393371582 Z M26.6453990936279,86.9503631591797 L11.4964637756348,86.9503631591797 L11.4964637756348,71.1702194213867 C11.4964637756348,69.9078140258789 10.2340526580811,68.645393371582 8.97164154052734,68.645393371582 C7.70922994613647,68.645393371582 5.81561279296875,69.9078140258789 5.81561279296875,71.1702194213867 L5.81561279296875,88.8439712524414 C5.81561279296875,90.1063766479492 7.07802438735962,91.3688049316406 8.34043598175049,91.3688049316406 L26.0141944885254,91.3688049316406 C27.2766036987305,91.3688049316406 28.5390148162842,90.7375946044922 28.5390148162842,88.8439712524414 C28.5390148162842,87.5815734863281 27.2766056060791,86.9503631591797 26.6453971862793,86.9503631591797 Z" p-id="2128" fill="#FFD81E06" stroke="Null"></path> <path d="M19.070930480957,17.5177307128906 L19.070930480957,78.7446899414063 L81.5602874755859,78.7446899414063 L81.5602874755859,17.5177307128906 L19.070930480957,17.5177307128906 Z M69.5673828125,50.9716300964355 L31.0638370513916,50.9716300964355 C28.5390148162842,50.9716300964355 27.2766056060791,49.7092208862305 27.2766056060791,47.184398651123 C27.2766056060791,44.6595726013184 28.5390148162842,43.3971633911133 31.0638370513916,43.3971633911133 L69.5673828125,43.3971633911133 C72.0922088623047,43.3971633911133 73.3546142578125,44.6595726013184 73.3546142578125,47.184398651123 C73.3546142578125,49.7092208862305 70.8298034667969,50.9716300964355 69.5673828125,50.9716300964355 Z" p-id="2129" fill="#FFD81E06" stroke="Null"></path>
1
2⑧fxBarCodeScanner1屬性設定
SdkConfig.ScanTips
:設定掃瞄界面顯示的掃瞄提示=將二維碼/條碼放入框內,即可自動掃瞄
。SdkConfig.ScanTitle
:設定掃瞄界面顯示的標題=二維碼/條碼
。
⑨fxSuperButtonCode屬性設定
Height
:設定控制元件高度=95
。Width
:設定控制元件寬度=100
。ButtonType
:設定按鈕型別,設定為TfxSvgButton
。Name
:設定控制元件名稱=fxSuperButtonCode
。ButtonType.SvgData
:設定SVG數據,其數據內容如下。
<path d="M5.49995422363281,44.8822822570801 L47.3823356628418,44.8822822570801 L47.3823394775391,3 L5.49995422363281,3 L5.49995422363281,44.8822822570801 Z M15.9706258773804,13.47057056427 L36.9117698669434,13.47057056427 L36.9117698669434,34.4117126464844 L15.9706258773804,34.4117126464844 L15.9706258773804,13.47057056427 Z M52.6176719665527,3 L52.6176719665527,44.882381439209 L94.5000457763672,44.882381439209 L94.5000457763672,3 L52.6176719665527,3 Z M84.0293884277344,34.4117126464844 L63.0882415771484,34.4117126464844 L63.0882415771484,13.47057056427 L84.0293731689453,13.47057056427 L84.0293884277344,34.4117126464844 Z M21.2058601379395,29.1764755249023 L31.6764297485352,29.1764755249023 L31.6764297485352,18.7058067321777 L21.2058601379395,18.7058067321777 L21.2058601379395,29.1764755249023 Z M5.49995422363281,92 L47.3823356628418,92 L47.3823394775391,50.1176147460938 L5.49995422363281,50.1176147460938 L5.49995422363281,92 Z M15.9706258773804,60.5881843566895 L36.9117698669434,60.5881843566895 L36.9117698669434,81.5293197631836 L15.9706258773804,81.5293273925781 L15.9706258773804,60.5881843566895 Z M78.7941436767578,18.7058067321777 L68.3234710693359,18.7058067321777 L68.3234710693359,29.1763744354248 L78.7940368652344,29.1763744354248 L78.7940368652344,18.7058067321777 Z M52.6176719665527,92 L63.0882415771484,92 L63.0882415771484,81.5294342041016 L52.6176719665527,81.5294342041016 L52.6176719665527,92 Z M63.0882415771484,60.5881843566895 L63.0882415771484,81.5293197631836 L73.5588226318359,81.5293197631836 L73.5588226318359,60.5881843566895 L63.0882415771484,60.5881843566895 Z M84.0293884277344,81.5294342041016 L73.5588226318359,81.5294342041016 L73.5588226318359,92 L94.4999694824219,92 L94.4999542236328,71.0587615966797 L84.0293884277344,71.0587615966797 L84.0293884277344,81.5294342041016 Z M84.0293884277344,60.5881843566895 L94.4999542236328,60.5881843566895 L94.4999542236328,50.1176147460938 L84.0293884277344,50.1176147460938 L84.0293884277344,60.5881843566895 Z M52.6176719665527,50.1176147460938 L52.6176719665527,60.5881843566895 L63.0882415771484,60.5881843566895 L63.0882415771484,50.1176147460938 L52.6176719665527,50.1176147460938 Z M21.2058601379395,76.2940902709961 L31.6764297485352,76.2940902709961 L31.6764297485352,65.8235168457031 L21.2058601379395,65.8235168457031 L21.2058601379395,76.2940902709961 Z" p-id="3413" fill="#FFD81E06" stroke="Null"></path>
1⑩fxMemo1屬性設定
Height
:設定控制元件高度=245
。Width
:設定控制元件寬度=360
。
(11)fxQRCode1屬性設定
Height
:設定控制元件高度=130
。Width
:設定控制元件寬度=140
。QuietZone
:設定二維碼周邊空白區域的大小=4
。
# 3. 程式設計
點選程式設計界面右下角的按鈕,切換至單元選擇界面,勾選需要使用的單元。程式需要引用BarCodeScanner
單元。
# 3.1. 程式初始設定
將掃瞄控制元件中的設定按照開關的初始設定進行設定。
Begin
//初始化
fxBarcodeScanner1.SdkConfig.Flashlight := fxSwitchFlash.IsChecked;
fxBarcodeScanner1.SdkConfig.ShowScanFromPhotoButton := fxSwitchPhoto.IsChecked;
fxBarcodeScanner1.SdkConfig.ToastResult := fxSwitchResult.IsChecked;
fxBarcodeScanner1.SdkConfig.Vibrate := fxSwitchViberate.IsChecked;
fxBarcodeScanner1.SdkConfig.PlayVoice := fxSwitchVoice.IsChecked;
End.
2
3
4
5
6
7
8
# 3.2. 事件設定
- ①fxSwitchVoice-OnSwitch事件
點選切換開啟/關閉提示音。
Procedure fxSwitchVoiceOnSwitch(Sender: TObject);
//提示音
Begin
fxBarcodeScanner1.SdkConfig.PlayVoice := fxSwitchVoice.IsChecked;
End;
2
3
4
5
- ②fxSwitchViberate-OnSwitch事件
點選切換開啟/關閉振動。
Procedure fxSwitchViberateOnSwitch(Sender: TObject);
//振動
Begin
fxBarcodeScanner1.SdkConfig.Vibrate := fxSwitchViberate.IsChecked;
End;
2
3
4
5
- ④fxSwitchFlash-OnSwitch事件
點選切換開啟/關閉閃光燈。
Procedure fxSwitchFlashOnSwitch(Sender: TObject);
//閃光燈開啟關閉
Begin
fxBarcodeScanner1.SdkConfig.Flashlight := fxSwitchFlash.IsChecked;
End;
2
3
4
5
- ⑤fxSwitchPhoto-OnSwitch事件
點選開啟/關閉在掃瞄界面顯示相簿按鈕。
Procedure fxSwitchPhotoOnSwitch(Sender: TObject);
//是否顯示相簿
Begin
fxBarcodeScanner1.SdkConfig.ShowScanFromPhotoButton := fxSwitchPhoto.IsChecked;
End;
2
3
4
5
- ⑥fxSwitchResult-OnSwitch事件
點選以開啟/關閉顯示掃瞄結果提示。
Procedure fxSwitchResultOnSwitch(Sender: TObject);
//顯示掃瞄結果
Begin
fxBarcodeScanner1.SdkConfig.ToastResult := fxSwitchResult.IsChecked;
End;
2
3
4
5
- ⑦fxSuperButtonScan-OnClick事件
點選以開啟掃瞄。
Procedure fxSuperButtonScanOnClick(Sender: TObject);
//開啟掃瞄
Begin
fxBarcodeScanner1.Start;
End;
2
3
4
5
- ⑧fxBarCodeScanner1-OnScanComletedCallbackEvent事件
當掃瞄完成時,如果連續掃瞄按鈕處於開啟狀態則繼續進行下一次掃瞄。
Procedure fxBarcodeScanner1OnScanComletedCallbackEvent(Sender: TObject; ResultCode: Integer; ResultString: string);
//連續掃瞄模式
Begin
fxMemo1.Lines.Add(ResultString);
if fxSwitchScan.IsChecked Then
fxBarcodeScanner1.Start;
End;
2
3
4
5
6
7
- ⑨fxSuperButtonCode-OnClick事件
點選按鈕,將文字框中的內容轉換為二維碼。
Procedure fxSuperButtonCodeOnClick(Sender: TObject);
//顯示二維碼
Begin
fxQRCode1.Text := fxMemo1.Text;
End;
2
3
4
5
- 程式定義
- 程式需要引用
BarCodeScanner
單元。
- 程式需要引用
//引用BarCodeScanner單元
Procedure fxSwitchVoiceOnSwitch(Sender: TObject);
//fxSwitchVoice的OnSwitch事件,提示音
Begin
fxBarcodeScanner1.SdkConfig.PlayVoice := fxSwitchVoice.IsChecked;
End;
Procedure fxSwitchViberateOnSwitch(Sender: TObject);
//fxSwitchViberate的OnSwitch事件,振動
Begin
fxBarcodeScanner1.SdkConfig.Vibrate := fxSwitchViberate.IsChecked;
End;
Procedure fxSwitchFlashOnSwitch(Sender: TObject);
//fxSwitchFlash的OnSwitch事件,閃光燈開啟關閉
Begin
fxBarcodeScanner1.SdkConfig.Flashlight := fxSwitchFlash.IsChecked;
End;
Procedure fxSwitchPhotoOnSwitch(Sender: TObject);
//fxSwitchPhoto的OnSwitch事件,是否顯示相簿
Begin
fxBarcodeScanner1.SdkConfig.ShowScanFromPhotoButton := fxSwitchPhoto.IsChecked;
End;
Procedure fxSwitchResultOnSwitch(Sender: TObject);
//fxSwitchResult的OnSwitch事件,顯示掃瞄結果
Begin
fxBarcodeScanner1.SdkConfig.ToastResult := fxSwitchResult.IsChecked;
End;
Procedure fxBarcodeScanner1OnScanComletedCallbackEvent(Sender: TObject; ResultCode: Integer; ResultString: string);
//fxBarcodeScanner1的OnScanComletedCallbackEvent,連續掃瞄模式
Begin
fxMemo1.Lines.Add(ResultString);
if fxSwitchScan.IsChecked Then
fxBarcodeScanner1.Start;
End;
Procedure fxSuperButtonScanOnClick(Sender: TObject);
//fxSuperButtonScan的OnClick事件,點選以開啟掃瞄
Begin
fxBarcodeScanner1.Start;
End;
Procedure fxSuperButtonCodeOnClick(Sender: TObject);
//fxSuperButtonCode的OnClick事件,點選以顯示二維碼
Begin
fxQRCode1.Text := fxMemo1.Text;
End;
Begin
//初始化
fxBarcodeScanner1.SdkConfig.Flashlight := fxSwitchFlash.IsChecked;
fxBarcodeScanner1.SdkConfig.ShowScanFromPhotoButton := fxSwitchPhoto.IsChecked;
fxBarcodeScanner1.SdkConfig.ToastResult := fxSwitchResult.IsChecked;
fxBarcodeScanner1.SdkConfig.Vibrate := fxSwitchViberate.IsChecked;
fxBarcodeScanner1.SdkConfig.PlayVoice := fxSwitchVoice.IsChecked;
End.
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# 4. 運行結果
使用滑鼠在 PinToo 功能表,點選[儲存至資料庫]
按鈕,將其儲存至資料庫,點選[除錯運行]
確認能夠正常打開。
通過同步中心,將程式上傳至手機PinToo運行;同步時,請確保手機已經運行PinToo,並且已經登陸。
在該程式下,選擇掃瞄選項,點選掃瞄按鈕打開掃瞄界面,將攝像頭對準包含二維碼或者條形碼的物體,待識別后返回程式,並在編輯框中顯示掃瞄識別的結果。如果啟用了連續掃瞄則在掃瞄完成後將繼續執行下一次掃瞄,直至手動點選左上角返回程式。在編輯框中包含內容的情況下,點選二維碼產生的按鈕,在右下方會顯示內容轉換的二維碼。