This sample project shows how to use and manipulate the camera of a device. The sample demonstrates the use of the TCameraComponent.
- 1 Location
- 2 Description
- 3 How to Use the Sample
- 4 Files
- 5 Implementation
- 6 Uses
- 7 See Also
You can find the CameraComponent sample project at:
- Start | Programs | Embarcadero RAD Studio Sydney | Samples and then navigate to:
- CPP\Mobile Snippets\CameraComponent\
- Object Pascal\Mobile Snippets\CameraComponent\
- Subversion Repository:
- You can find Delphi and C++ code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.
This sample demonstrates the use of the TCameraComponent, which is the nonvisual component for a camera device.
The sample project shows how to manipulate the camera of a device, and how to set preset and custom quality capture settings for your camera. With this sample you can:
- Turn on and off the camera of your device.
- Select either the front facing camera or the back facing camera.
- Set different resolution configurations for your camera.
- Select whether to turn the flash on, off, or leave it in automatic mode.
How to Use the Sample
- Navigate to one of the locations given above and open:
- Delphi: CameraComponent.dproj
- C++: CameraComponent.cbproj
- In the Projects Window, select the target platform.
- Note: The device where you run the application must have a camera.
- Press F9 or choose Run > Run.
- The available Camera Resolutions are automatically filled in the cbResolutions combo box.
- To interact with the sample:
- Use the Start Camera and Stop Camera buttons to enable and disable the camera component.
- Use the Front and Back buttons of the Camera Type section to change between the front and back camera of your device.
- Change the Camera Resolutions by:
- Using the Low, Medium, High, or Photo preset resolutions.
- Selecting a resolution from the cbResolutions combo box to get a custom resolution based on the available ones. Use the cbPriority combo box to set how the resolutions must be arranged, either prioritizing the resolution or the frame rate.
- Use the On, Off, and Auto buttons available in the Camera Torch Type section to manage the camera torch.
|File in Delphi||File in C++||Contains|
The project itself.
The main form where the components are located.
Delphi source file, C++ header file, and C++ implementation file respectively.
Basic information about this sample.
The Active property is used to turn on and off the camera.
The TVideoCaptureSetting record is used to store a single camera frame rate with its corresponding resolution.
Viewing the Camera Captured Data
The event handler written for the OnSampleBufferReady event, synchronizes the CurrentThread, that represents the main thread, with the method to capture and display the data. Synchronize is used to execute the SampleBufferToBitmap method within the main thread.
Ensuring the Camera is Released When Required
When the form is created, the sample checks whether the IFMXApplicationEventService platform service is supported, this service will allow you to enable or disable the camera when the application goes to background.
TApplicationEvent is used to check the different application events to ensure the camera is released when the app goes away in the following cases:
- Warning: It is important that the camera is released as required; otherwise the camera will remain engaged by the app (even after going to background), and other apps will not have access to use the camera.
Changing the Camera Type
Since the front and back camera of a device tend to have different resolutions; when the camera changes, the available resolutions are updated.
Setting the Quality of the Captured Video Data
The Quality property is used to set the quality of the video capture. It is possible to set preset or custom camera quality:
Preset Camera Quality
Custom Camera Quality
To set a custom camera quality, the sample sets the
Quality property to
CaptureSettings. Then, the AvailableCaptureSettings property is used to capture the settings available in the selected camera. These settings are then displayed in the cbResolutions TComboBox so the user can select the wanted custom camera quality. When combo box changes the CaptureSetting property is used to set the selected custom camera settings.
To gather the AvailableCaptureSettings, the sample determines the priority criterion to sort the results using the CaptureSettingPriority property. The two possible capture settings priorities are
Using the Torch