How to set the zoom back of the camera with fast expansion

I am trying to make the application fast and I want to use the front camera. I used AVFoundation and tried some codes. But I could not set the front scaling option. Is it possible? For the rear view camera, everything worked successfully.

I do not want to use Affine Transform. Because it can lead to lower image quality. So how can I set this parameter programmatically?

Thanks.

+5
source share
1 answer

You will need to add the zoomFactor variable to your camera.

var zoomFactor: CGFloat = 1.0 

Next, determine the scaling of the function to be used with the recognition pinch. I assume that you have created a front capture and input device. frontDevice is an additional capture device on my camera. This is how I scale this device.

  public func zoom(pinch: UIPinchGestureRecognizer) { guard let device = frontDevice else { return } func minMaxZoom(_ factor: CGFloat) -> CGFloat { return min(max(factor, 1.0), device.activeFormat.videoMaxZoomFactor) } func update(scale factor: CGFloat) { do { try device.lockForConfiguration() defer { device.unlockForConfiguration() } device.videoZoomFactor = factor } catch { debugPrint(error) } } let newScaleFactor = minMaxZoom(pinch.scale * zoomFactor) switch pinch.state { case .began: fallthrough case .changed: update(scale: newScaleFactor) case .ended: zoomFactor = minMaxZoom(newScaleFactor) update(scale: zoomFactor) default: break } } 

Finally, add a pinch recognizer to some view.

  let pgr = UIPinchGestureRecognizer(target: self, action: #selector(zoom)) view.addGestureRecognizer(pgr) 
+1
source

Source: https://habr.com/ru/post/1247123/


All Articles