IQMediaPickerController
IQMediaPickerController copied to clipboard
How can i add zoom in-out when capturing image from camera?
I want to zoom in/out and capture image, but the camera view won't zoom.
This feature isn't available atm. I need to implement it.
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;
Thanks for the code sample. I'll review it and implement it once I get a chance.