1 unit Unit1; 2 3 interface 4 5 uses 6 System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Media, 8 FMX.Controls.Presentation, FMX.StdCtrls; 9 10 type 11 TForm1 = class(TForm) 12 CameraComponent1: TCameraComponent;//闪光灯的控制控件 13 Button1: TButton; 14 procedure FormCreate(Sender: TObject); 15 procedure Button1Click(Sender: TObject); 16 private 17 { Private declarations } 18 public 19 { Public declarations } 20 end; 21 22 var 23 Form1: TForm1; 24 25 implementation 26 27 {$R *.fmx} 28 {$R *.NmXhdpiPh.fmx ANDROID} 29 30 procedure TForm1.Button1Click(Sender: TObject); 31 begin 32 if Button1.Text = ‘开‘ then 33 begin 34 CameraComponent1.TorchMode := TTorchMode.tmModeOn;//开灯 35 Button1.Text := ‘关‘; 36 end 37 else 38 begin 39 CameraComponent1.TorchMode := TTorchMode.tmModeOff;//关灯 40 Button1.Text := ‘开‘; 41 end; 42 end; 43 44 procedure TForm1.FormCreate(Sender: TObject); 45 begin 46 Button1.Enabled := CameraComponent1.HasFlash;//如果没有闪光灯,则按钮不起作用 47 CameraComponent1.Active := True; 48 end; 49 50 end.
时间: 2024-11-01 22:35:09