大佬教程收集整理的这篇文章主要介绍了objective-c – 如何在iPhone SDK中自动拍摄照片?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我想知道用户是否有可能不必按下按钮来捕捉帧.是否可以通过自动对焦自动捕获当前帧?就像用户只需将相机放置在图像上一秒钟,当图像聚焦得很好时,它会自动捕获,这样用户就可以移动到下一个图像而无需按任何按钮?
我捕获帧的代码如下:
- (void)initCapture { AVCaptureDeviceInput *captureInput = [AVCaptureDeviceInput deviceInputWithDevice:[AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo] error:nil]; AVCaptureVideoDataOutput *captureOutput = [[AVCaptureVideoDataOutput alloc] init]; captureOutput.alwaysDiscardsLateVideoFrames = YES; /*We create a serial queue to handle the processing of our frames*/ dispatch_queue_t queue; queue = dispatch_queue_create("cameraQueue",null); [captureOutput setSampleBufferDelegate:self queue:queue]; dispatch_release(queuE); // Set the video output to store frame in BGRA (it is supposed to be faster) NSString* key = (NSString*)kCVPixelBufferPixelFormatTypeKey; NSnumber* value = [NSnumber numberWithUnsignedInt:kCVPixelFormatType_32BGRA]; NSDictionary* videoSetTings = [NSDictionary DictionaryWithObject:value forKey:key]; [captureOutput setVideoSetTings:videoSetTings]; /*And we create a capture session*/ captureSession = [[AVCaptureSession alloc] init]; /*We add input and output*/ [captureSession addInput:captureInput]; [captureSession addOutput:captureOutput]; AVCaptureConnection *conn = [captureOutput connectionWithMediaType:AVMediaTypeVideo]; if (conn.supportsVideoMinFrameDuration) conn.videoMinFrameDuration = CMTimeMake(5,1); if (conn.supportsVideoMaxFrameDuration) conn.videoMaxFrameDuration = CMTimeMake(5,1); [captureSession setSessionPreset:AVCaptureSessionPresetPhoto]; customLayer = [CALayer layer]; customLayer.frame = self.view.bounds; customLayer.transform = CATransform3DRotate(CATransform3DIdentity,M_PI/2.0f,1); customLayer.contentsGravity = kCAGravityResizeAspectFill; //[self.view.layer addSublayer:customLayer]; /*We add the imageView*/ imageView = [[UIImageView alloc] init]; imageView.frame = CGRectMake(0,100,100); //imageView.frame = self.view.bounds; [self.view addSubview:imageView]; [captureSession startRunning]; }
我将非常感谢你的帮助.
谢谢.
[[[captureManager videoInput] device] addObserver:self forKeyPath:@"adjusTingFocus" options:NSKeyValueObservingOptionNew context:nil];
然后添加observeValueForKeyPath方法,该方法在调整焦点完成时拍摄照片:
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { if( [keyPath isEqualToString:@"adjusTingFocus"] ){ BOOL adjusTingFocus = [ [change objectForKey:NSKeyValueChangeNewKey] isEqualTonumber:[NSnumber numberWithInt:1] ]; if (!adjusTingFocus) { [[self captureManager] captureStillImage:self]; } } }
以上是大佬教程为你收集整理的objective-c – 如何在iPhone SDK中自动拍摄照片?全部内容,希望文章能够帮你解决objective-c – 如何在iPhone SDK中自动拍摄照片?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。