Search code examples
iosfoundationavcapturedevice

iOS AVFoundation extend zoom out level


I'm develop an iOS scanning app using AVFoundation. I can set the zoom level of AVCaptureDevice by calling videoZoomFactor. But the problem is the maximum zoom out level so that the camera can take whole picture of A4 paper is 20 cm. How can we reduce this for example 13-14 cm? Anyway to scale the VideoPreviewLayer?

Any also anyway that we can fix the focus point at 15 cm? (camera only try to focus on fix position)?


Solution

  • You can directly zoom the preview layer by using CoreGraphics. Here is the example code.

    // zoom the preview view using core graphics
     [previewView setTransform:CGAffineTransformMakeScale(2.0, 2.0 )];
    

    To fix the focus point you can use below property from AVCaptureDevice

    @property(nonatomic) CGPoint focusPointOfInterest;
    

    Note that focus point of interest values (0,0) indicates that the camera should focus on the top left corner of the image, while a value of (1,1) indicates that it should focus on the bottom right. The default value is (0.5,0.5)