Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
VickyPrajapati24 opened this issue Aug 30, 2018 · 3 comments
Open

Comments

@VickyPrajapati24
Copy link

VickyPrajapati24 commented Aug 30, 2018

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

@VickyPrajapati24 VickyPrajapati24 changed the title How can i add zoom in-out when capturing image from camera view? How can i add zoom in-out when capturing image from camera? Aug 30, 2018
@hackiftekhar
Copy link
Owner

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

@VickyPrajapati24
Copy link
Author

VickyPrajapati24 commented Sep 7, 2018

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;

@hackiftekhar
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants