使用GPUImageView时添加聚焦功能

` -(void)setupFilter{
//创建摄像头视图 GPUImageView *filterView = [[GPUImageView alloc]initWithFrame:self.view.bounds]; UITapGestureRecognizer tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapOnVideoView:)]; [filterView addGestureRecognizer:tap]; } //聚焦 -(void)tapOnVideoView:(UITapGestureRecognizer)recognizer{

CGPoint point =  [recognizer locationInView:recognizer.view];
UIView *preView = recognizer.view;
CGPoint focusPoint = CGPointMake(point.x/preView.width, point.y/preView.height);
NSError *error;
if([videoCamera.inputCamera lockForConfiguration:&error]){
    //对焦模式和对焦点,设定前一定要判断该模式是否支持,如果支持就先设定位置,然后再设定模式,单独设定位置是没有用的。曝光设置跟这里一样的原理
    if([videoCamera.inputCamera isFocusModeSupported:AVCaptureFocusModeAutoFocus]){
        [videoCamera.inputCamera setFocusPointOfInterest:focusPoint];
        [videoCamera.inputCamera setFocusMode:AVCaptureFocusModeAutoFocus];
    }
    //曝光模式和曝光点
    if([videoCamera.inputCamera isExposureModeSupported:AVCaptureExposureModeAutoExpose]){
        [videoCamera.inputCamera setExposurePointOfInterest:focusPoint];
        [videoCamera.inputCamera setExposureMode:AVCaptureExposureModeAutoExpose];
    }
    
    //当你lockForConfiguration后,完成设置后记住一定要unlock
    [videoCamera.inputCamera unlockForConfiguration];
    
    
    //设置对焦动画
    _focusPoint.center = point;
    _focusPoint.hidden = NO;
    [UIView animateWithDuration:0.3f animations:^{
        _focusPoint.transform = CGAffineTransformMakeScale(1.25, 1.25);
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:0.5f animations:^{
            _focusPoint.transform = CGAffineTransformIdentity;
        } completion:^(BOOL finished) {
            _focusPoint.hidden = YES;
        }];
        
    }];
    
}

}

` 其实实现这个功能还是很简单的,关于设置的顺序,可以点击相应的属性进去看看,文档里说的很清楚,建议大家还是要仔细看看,自己亲身体会一下。

转载于:https://my.oschina.net/NycoWang/blog/898347

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值