Skip to content

TTMSFNCWXCamera

The TTMSFNCWXCamera is a component to access and show a stream of the selected camera.

Requirements

macOS requires internet connection.

The minimum required iOS version is 14.6.

Control the camera

On macOS an internet connection is required as the camera file needs to be loaded from an online source. So as a first step, set the public FileLocation property to cflOnline.

The camera stream needs to be started manually:

procedure TForm1.Button1Click(Sender: TObject);
begin
 TTMSFNCWXCamera1.Start;
end;

The camera feed can be paused or stopped by calling TTMSFNCWXCamera.Pause and TTMSFNCWXCamera.Stop.

List of available camera devices

The TTMSFNCWXCamera picks a default camera automatically. It’s possible to change this behaviour by requesting a list of available camera devices, but keep in mind this functionality requires internet connection in native applications. For WEB it’s expected that the application will be hosted in a secure context.

Change the TTMSFNCWXCamera.CameraType property to wctSelected to enable camera device selection. After that, call TTMSFNCWXCamera.RequestDevices to request a list of the available devices. This list of devices can be accessed once the OnCameraDevicesInitialized event is triggered.

procedure TForm2.FormCreate(Sender: TObject);
begin
 TMSFNCWXCamera1.CameraType := wctSelected;
 TMSFNCWXCamera1.RequestDevices;
end;
procedure TForm2.TMSFNCWXCamera1CameraDevicesInitialized(Sender: TObject);
begin
 if TMSFNCWXCamera1.Devices.Count > 0 then
 begin
 TMSFNCWXCamera1.SelectDevice(TMSFNCWXCamera1.Devices.Items[0]);
 TMSFNCWXCamera1.Start;
 end;
end;

Take a snapshot

Taking a snapshot of the current camera feed is as simple as calling TTMSFNCWXCamera.TakeSnapshot and implementing the TTMSFNCWXCamera.OnSnapshot event. The TakeSnapshot method has an AFormat parameter which will determine if the snapshould should be created as PNG or JPEG. By default it is created as PNG.

procedure TForm1.FormCreate(Sender: TObject);
begin
 TMSFNCWXCamera1.TakeSnapshot;
end;
procedure TForm1.TMSFNCWXCamera1Snapshot(Sender: TObject;
 ABitmap: TTMSFNCBitmap);
begin
 ABitmap.SaveToFile('path\to\picture.png');
end;