The new camera component in Delphi for iOS makes it really easy to invoke the flash on your iPhone, iPod or iPad.
This allows you to build a flashlight application which can come in really handy when looking for keys in your bag at night or anytime you don’t have an actual flashlight nearby.
For this app, we used the new TCameraComponent, and several graphics for the UI. The ‘on’ button and ‘off’ button are both images that we show and hide depending on whether or not the flash is active. Also, the black flashlight is an image, and the yellow light image that is shown on screen when the flash is invoked is a transparent png.
procedure TFlashLightForm.SetFlashlightState(Active : Boolean);
begin
if Active then
begin
Camera.TorchMode := TTorchMode.tmModeOn;
end else
Camera.TorchMode := TTorchMode.tmModeOff;
end;procedure TFlashLightForm.FormCreate(Sender: TObject);
begin
ImageOff.Enabled := Camera.HasFlash;
Camera.Active := True;
end;procedure TFlashLightForm.ImageOffClick(Sender: TObject);
begin
ImageOff.Visible := False;
ImageOn.Visible := True;
SetFlashlightState(True);
Light.Visible := True;
end;procedure TFlashLightForm.ImageOnClick(Sender: TObject);
begin
ImageOff.Visible := True;
ImageOn.Visible := False;
SetFlashlightState(False);
Light.Visible := False;
end;
Below is a quick video of the flashlight app in action:
Regards,
Sarina
Learn more about Delphi for iOS by visiting http://embt.co/RADStudioiOS