如何在不按imagepickercontroller上的拍照按钮的情况下自动拍照? [英] How to automatically take a picture without pressing the phototaken button on the imagepickercontroller?

查看:28
本文介绍了如何在不按imagepickercontroller上的拍照按钮的情况下自动拍照?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我需要每隔一分钟自动拍照.但我找不到任何解决方案.

In my project, I need to take pictures automatically every one minute. But I can't find out any solutions.

这是我实现的代码,但它不起作用...

This is the code which I implemented but it doesn't work...

我使用 NSTimer 调用相机每 4 秒拍照一次.而我只需要拍摄

I used a NSTimer to call up the camera to take pictures every 4 sec. And I only need the takepic

//This method is all for the time setup. You can ignore it.

-(NSDate *)userInfo {

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];

[dateFormatter setDateFormat:@"yyyy-MM-dd 'at' HH:mm:ss"];

NSDate *date = [[[NSDate alloc]init]autorelease];

NSString *formattedDateString = [dateFormatter stringFromDate:date];

NSLog(@"formattedDateString: %@", formattedDateString);   

return date;    
}


- (void)targetMethod:(NSTimer *)theTimer {
   NSDate *startDate = [self userInfo];

   //newly changed lines.
   UIImagePickerController *myPicker;
   [myPicker takePicture];
   NSLog(@"Timer started on %@", startDate);

}


- (IBAction) showCameraUI {


   [NSTimer scheduledTimerWithTimeInterval:4.0
                                 target:self
                               selector: @selector(targetMethod:)
                               userInfo:[self userInfo]
                                repeats:YES];

}

推荐答案

我终于找到了解决方案.

Finally I figured out the solution.

我使用

 AVCaptureVideoDataOutputSampleBufferDelegate

自动拍照.

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer   
   fromConnection:(AVCaptureConnection *)connection 

这很简单,谢谢@sch 的帮助:)

It is pretty simple and thank you @sch all the same for your help :)

这篇关于如何在不按imagepickercontroller上的拍照按钮的情况下自动拍照?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆