AVCaptureDevice Camera Zoom

前端 未结 9 696
没有蜡笔的小新
没有蜡笔的小新 2021-01-31 19:51

I have a simple AVCaptureSession running to get a camera feed in my app and take photos. How can I implement the \'pinch to zoom\' functionality using a UIGestureRecognize

9条回答
  •  灰色年华
    2021-01-31 19:59

    I am using iOS SDK 8.3 and the AVfoundation framework and for me using the following method worked for :

    nameOfAVCaptureVideoPreviewLayer.affineTransform = CGAffineTransformMakeScale(scaleX, scaleY) 
    

    For saving the picture with the same scale I used the following method:

    nameOfAVCaptureConnection.videoScaleAndCropFactor = factorNumber; 
    

    The code bellow is for getting the image in the scale

    [stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnnection completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {
            if(imageDataSampleBuffer != NULL){
    
                NSData *imageData = [AVCaptureStillImageOutput  jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
                UIImage *image = [UIImage imageWithData:imageData];
    }
    }];
    

提交回复
热议问题