How to adjust the camera's focal length (zoom function)?
ZEGO provides camera zoom function. By setting the zoom factor of the camera through the SDK, you can achieve the effect of magnifying distant objects when shooting.
Usage Steps
Get the Maximum Zoom Factor of the Camera
Call the getCameraMaxZoomFactor interface to get the maximum zoom factor of the camera. The interface is only effective after the camera is successfully started. It is recommended to call it after receiving the onPublisherCapturedVideoFirstFrame callback.
- iOS
- (void)onPublisherCapturedVideoFirstFrame:(ZegoPublishChannel)channel {
self.maxZoomFactor = [[ZegoExpressEngine sharedEngine] getCameraMaxZoomFactor];
}- Android
ZegoExpressEngine.getEngine().setEventHandler(new IZegoEventHandler() {
@Override
public void onPublisherCapturedVideoFirstFrame(ZegoPublishChannel channel) {
float maxZoomFactor=ZegoExpressEngine.getEngine().getCameraMaxZoomFactor();
}
});- uni-app
this.engine.on("publisherCapturedVideoFirstFrame", (channel) => {
let maxZoomFactor = this.engine.getCameraMaxZoomFactor();
});Set Camera Zoom Factor
Call the setCameraZoomFactor interface to set the zoom factor of the camera. The minimum value is "1.0", and the maximum value can be obtained from the getCameraMaxZoomFactor interface.
When the camera is restarted, such as switching between front and rear cameras, disabling the camera and then restarting it, or setting mirroring, the zoom factor will be restored to the initial value.
- iOS
[[ZegoExpressEngine sharedEngine] setCameraZoomFactor:self.maxZoomFactor];- Android
ZegoExpressEngine.getEngine().setCameraZoomFactor(maxZoomFactor);- uni-app
this.engine.setCameraZoomFactor(maxZoomFactor);