AVCapture中实现拉近拉远镜头

这段代码在我机器上运行貌似一直出错,我后来是这样写的:

//写了这几句话 貌似远点了  1224

        [self.captureSession beginConfiguration];

        self.device.videoZoomFactor = 50.0f;

        AVCaptureStillImageOutput* output = (AVCaptureStillImageOutput*)[self.captureSession.outputs objectAtIndex:0];

        AVCaptureConnection *videoConnection = [output connectionWithMediaType:AVMediaTypeVideo];

        CGFloat maxScale = videoConnection.videoMaxScaleAndCropFactor;

        CGFloat zoom = maxScale / 50;

//        videoConnection.videoScaleAndCropFactor -= zoom;

        videoConnection.videoScaleAndCropFactor = 1.0f;

        [self.captureSession commitConfiguration];





转载自:http://blog.csdn.net/song_yu_tao/article/details/17305601


自己用avcapture实现自定制相机,系统相机是可以拉近拉远镜头的,网上搜寻了半天始终没有发现,刚才又翻看了半天的api接口,终于找到了,原来他藏在AVCaptureConnection中,videoScaleAndCropFactor:缩放裁剪系数。简单写了下使用方法:

[objc]  view plain copy
  1. AVCaptureStillImageOutput* output = (AVCaptureStillImageOutput*)[self.captureSession.outputs objectAtIndex:0];  
  2. AVCaptureConnection *videoConnection = [output connectionWithMediaType:AVMediaTypeVideo];  
  3. CGFloat maxScale = videoConnection.videoMaxScaleAndCropFactor;  
  4. CGFloat zoom = maxScale / 50;  
  5. videoConnection.videoScaleAndCropFactor += zoom;  
  6. self.preVideoView.transform = CGAffineTransformScale(self.preVideoView.transform, zoom, zoom);  


其中preVideoView的layer中添加了AVCaptureVideoPreviewLayer。

你可能感兴趣的:(AVCapture中实现拉近拉远镜头)