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 在CODE上查看代码片 派生到我的代码片
  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。
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值