您的位置:首页 > 其它

AVCapture中实现拉近拉远镜头

2013-12-24 18:59 791 查看
这段代码在我机器上运行貌似一直出错,我后来是这样写的:

//写了这几句话 貌似远点了  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
plaincopy





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

AVCaptureConnection *videoConnection = [output connectionWithMediaType:AVMediaTypeVideo];  

CGFloat maxScale = videoConnection.videoMaxScaleAndCropFactor;  

CGFloat zoom = maxScale / 50;  

videoConnection.videoScaleAndCropFactor += zoom;  

self.preVideoView.transform = CGAffineTransformScale(self.preVideoView.transform, zoom, zoom);  

其中preVideoView的layer中添加了AVCaptureVideoPreviewLayer。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: