IQMediaPickerController icon indicating copy to clipboard operation
IQMediaPickerController copied to clipboard

How can i add zoom in-out when capturing image from camera?

Open VickyPrajapati24 opened this issue 6 years ago • 3 comments

I want to zoom in/out and capture image, but the camera view won't zoom.

VickyPrajapati24 avatar Aug 30 '18 08:08 VickyPrajapati24

This feature isn't available atm. I need to implement it.

hackiftekhar avatar Sep 07 '18 06:09 hackiftekhar

I have implemented it like below, 1) IQCaptureSession.m Comment below line //@property(nonatomic, readonly) AVCaptureDeviceInput *videoBackCaptureDeviceInput; Add below line @synthesize videoBackCaptureDeviceInput = _videoBackCaptureDeviceInput; 2) IQCaptureSession.h Add below line @property(nonatomic, readonly) AVCaptureDeviceInput *videoBackCaptureDeviceInput;

3) IQMediaView.h @property(nonatomic) AVCaptureDeviceInput *videoBackCaptureDeviceInput; 4) IQMediaView.m

-(void)setVideoBackCaptureDeviceInput:(AVCaptureDeviceInput *)videoBackCaptureDeviceInput
{
    _videoBackCaptureDeviceInput = videoBackCaptureDeviceInput;
}

-(void)pinchedCameraPreview:(UIPinchGestureRecognizer*)gesture
{
    AVCaptureDevice *device = _videoBackCaptureDeviceInput.device;
    AVCaptureDeviceFormat *format = device.activeFormat;
    const CGFloat pinchVelocityDividerFactor = 5.0f;
    if (gesture.state == UIGestureRecognizerStateChanged || gesture.state ==UIGestureRecognizerStateBegan)
    {
        NSError *error = nil;
        if ([device lockForConfiguration:&error])
        {
            CGFloat desiredZoomFactor = device.videoZoomFactor +
            atan2f(gesture.velocity, pinchVelocityDividerFactor);
            device.videoZoomFactor = MAX(1.0, MIN(desiredZoomFactor, format.videoMaxZoomFactor));
            [device unlockForConfiguration];
        }
        else
        {
            NSLog(@"error: %@", error);
        }
    }
}

5) IQMediaCaptureController.m Add below line in viewWillAppear just above this line self.mediaView.previewSession = [self session].captureSession;

self.mediaView.videoBackCaptureDeviceInput = [self session].videoBackCaptureDeviceInput;

VickyPrajapati24 avatar Sep 07 '18 06:09 VickyPrajapati24

Thanks for the code sample. I'll review it and implement it once I get a chance.

hackiftekhar avatar Sep 07 '18 09:09 hackiftekhar