本文主要是介绍AVfoundation中焦距的设置(slider实现拉近拉远镜头),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
首先设置一个slider
UISlider focusSlider = [[UISlideralloc]initWithFrame:CGRectMake(60,_bottomView.frame.origin.y-60,200,20)];
[focusSlideraddTarget:selfaction:@selector(AdjustFocusAction:)forControlEvents:UIControlEventValueChanged];
[focusSlidersetThumbImage:[UIImageimageNamed:@"camera_view_slider_take_gray.png"]forState:UIControlStateNormal];
[focusSlidersetMinimumTrackImage:[UIImageimageNamed:@"camera_view_sliderbar_gray.png"]forState:UIControlStateNormal];
[focusSlidersetMaximumTrackImage:[UIImageimageNamed:@"camera_view_sliderbar_gray.png"]forState:UIControlStateNormal];
[focusSlidersetBackgroundColor:[UIColorclearColor]];
[focusSlidersetMaximumValue:1];
[focusSlidersetMinimumValue:0];
[focusSlider setValue:0.0];
[self.viewaddSubview:focusSlider];
以下做一下有关相机的设置(只写出来了其中一部分,并非全部)
preview = [AVCaptureVideoPreviewLayerlayerWithSession:self.session];
self.preview.frame =CGRectMake(0,0, self.cameraView.frame.size.width,self.cameraView.frame.size.height);
[self.previewsetPosition:CGPointMake(CGRectGetMidX(self.cameraView.bounds),CGRectGetMidY(self.cameraView.bounds))];
self.preview.videoGravity =AVLayerVideoGravityResize;
[self.cameraView.layeraddSublayer:self.preview];
captureOutput = (AVCaptureStillImageOutput*)[self.session.outputsobjectAtIndex:0];
focusConnection =[captureOutput connectionWithMediaType:AVMediaTypeVideo];
调节焦距
-(void)AdjustFocusAction:(id)sender
{
[UIViewanimateWithDuration:0.025animations:^{
[self.previewsetAffineTransform:CGAffineTransformMakeScale([(UISlider *)sendervalue]+1, [(UISlider *)sendervalue]+1)];
focusConnection.videoScaleAndCropFactor = [(UISlider *)sendervalue]+1;
}];
}
这篇关于AVfoundation中焦距的设置(slider实现拉近拉远镜头)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!