Camera exposure and focus are commonly used in video calls to enable high-quality video capture. The Agora RTC SDK provides a set of camera management methods on the Android and iOS platforms, with which you can switch between the front and rear camera, set the camera zoom factor, set the exposure region and set the focus position.
Before proceeding, ensure that you have implemented basic real-time functions in your project.
Refer to the following steps to set the camera exposure and focus:
isCameraExposurePositionSupported
method to check whether exposure function is supported. If it is supported, call the setCameraExposurePosition
method to set the camera exposure.onCameraExposureAreaChanged
callback.isCameraAutoFocusFaceModeSupported
method to check whether auto face-focus function is supported. If it is supported, call the setCameraAutoFocusModeEnabled
method to set the focus.isCameraFocusSupported
method to check whether manual focus function is supported. If it is supported, call the setCameraFocusPositionInPreview
method to set the focus.onCameraFocusAreaChanged
callback.// Java
// Check whether exposure function is supported and enable exposure.
boolean shouldSetExposure = rtcEngine.isCameraExposurePositionSupported();
if (shouldSetExposure) {
// Set the camera exposure at (50, 100).
float positionX = 50.0f;
float positionY = 100.0f;
rtcEngine.setCameraExposurePosition(positionX, positionY);
}
// Check whether auto face-focus function is supported and enable auto-face focus.
boolean shouldSetFaceMode = rtcEngine.isCameraAutoFocusFaceModeSupported();
rtcEngine.setCameraAutoFocusFaceModeEnabled(shouldSetFaceMode);
// Check whether manual focus function is supported and set the focus.
boolean shouldManualFocus = rtcEngine.isCameraFocusSupported();
if (shouldManualFocus) {
// Set the camera focus at (50, 100).
float positionX = 50.0f;
float positionY = 100.0f;
rtcEngine.setCameraFocusPositionInPreview(positionX, positionY);
}
// The camera focus area is updated. You can monitor the update event and implement corresponding logic.
public void onCameraExposureAreaChanged(rect) {
}
// The camera exposure area is updated. You can monitor the update event the implement corresponding logic.
public void onCameraFocusAreaChanged(rect) {
}
// Swift
// Check whether exposure function is supported and enable exposure.
let isSupported = agoraKit.isCameraExposurePositionSupported()
if isSupported {
// Set the camera exposure at (50, 100).
let point = CGPoint(x: 50, y: 100)
agoraKit.setCameraExposurePosition(point)
}
// Check whether auto face-focus function is supported and enable auto-face focus.
let isSupported = agoraKit.isCameraAutoFocusFaceModeSupported()
agoraKit.setCameraAutoFocusFaceModeEnabled(isSupported)
// Check whether manual focus function is supported and set the focus.
let isSupported = agoraKit.isCameraFocusPositionInPreviewSupported()
if isSupported {
// Set the camera focus at (50, 100).
let point = CGPoint(x: 50, y: 100)
agoraKit.setCameraFocusPositionInPreview(point)
}
// The camera focus area is updated. You can monitor the update event and implement corresponding logic.
func rtcEngine(_ engine: AgoraRtcEngineKit, cameraExposureDidChangedToRect: CGRect) {
}
// The camera exposure area is updated. You can monitor the update event the implement corresponding logic.
func rtcEngine(_ engine: AgoraRtcEngineKit, cameraFocusDidChangedToRect: CGRect) {
}
// Objective-C
// Check whether exposure function is supported and enable exposure.
let isSuppported = [agoraKit isCameraExposurePositionSupported];
if (isSupported) {
// Set the camera exposure at (50, 100).
CGPoint *point = CGPointMake(50, 100);
[agoraKit setCameraExposurePosition: point];
}
// Check whether auto face-focus function is supported and enable auto-face focus.
Bool isSupported = [agoraKit isCameraAutoFocusFaceModeSupported];
[agoraKit setCameraAutoFocusFaceModeEnabled: isSupported];
// Check whether manual focus function is supported and set the focus.
let isSupported = [agoraKit isCameraFocusPositionInPreviewSupported];
if (isSupported) {
// Set the camera focus at (50, 100).
CGPoint *point = CGPointMake(50, 100);
[agoraKit setCameraFocusPositionInPreview: point];
}
// The camera focus area is updated. You can monitor the update event and implement corresponding logic.
- (void)rtcEngine:(AgoraRtcEngineKit * _Nonnull)engine cameraExposureDidChangedToRect:(CGRect)rect {
}
// The camera exposure area is updated. You can monitor the update event the implement corresponding logic.
- (void)rtcEngine:(AgoraRtcEngineKit * _Nonnull)engine cameraFocusDidChangedToRect:(CGRect)rect {
}
The following table shows the API comparison table of Java and Objective-C languages.
Java | Objective-C |
---|---|
isCameraExposurePositionSupported |
isCameraExposurePositionSupported |
setCameraExposurePosition |
setCameraExposurePosition |
isCameraAutoFocusFaceModeSupported |
isCameraAutoFocusFaceModeSupported |
setCameraAutoFocusModeEnabled |
setCameraAutoFocusModeEnabled |
isCameraFocusSupported |
isCameraFocusPositionInPreviewSupported |
setCameraFocusPositionInPreview |
setCameraFocusPositionInPreview |
onCameraExposureAreaChanged |
cameraExposureDidChangedToRect |
onCameraFocusAreaChanged |
cameraFocusDidChangedToRect |
Java
Objective-C