如何自动采取无pressing上imagepickercontroller的phototaken按钮的图片? [英] How to automatically take a picture without pressing the phototaken button on the imagepickercontroller?
本文介绍了如何自动采取无pressing上imagepickercontroller的phototaken按钮的图片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的项目,我需要自动拍照每隔一分钟。但是,我找不到任何解决方案。
这是code这是我实现的,但它不工作...
我用的NSTimer调出摄像头拍照每4秒。而我只需要takepic
//这个方法是所有的时间设置。你可以将其忽略。 - (*的NSDate)USERINFO {NSDateFormatter * dateFormatter = [[NSDateFormatter的alloc]初始化];[dateFormatter setDateFormat:@YYYY-MM-DD'为'HH:MM:SS];* NSDate的日期= [[[NSDate的页头] INIT]自动释放];* NSString的formattedDateString = [dateFormatter stringFromDate:日期];的NSLog(@formattedDateString:%@,formattedDateString);归期;
}
- (无效)targetMethod:(*的NSTimer)theTimer {
*的NSDate =的startDate [个体经营USERINFO] //新更改的行。
*的UIImagePickerController myPicker;
[myPicker takePicture]
的NSLog(@定时器开始在%@的startDate);}
- (IBAction为)showCameraUI {
[的NSTimer scheduledTimerWithTimeInterval:4.0
目标:自我
选择:@选择(targetMethod :)
用户信息:[个体经营USERINFO]
重复:YES];}
解决方案
最后我想出的解决方案。
我用
AVCaptureVideoDataOutputSampleBufferDelegate
要自动拍照。
- (无效)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)连接
这是pretty简单,谢谢@sch都一样对您有所帮助:)
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...
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.
I use the
AVCaptureVideoDataOutputSampleBufferDelegate
to take pictures automatically.
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection
It is pretty simple and thank you @sch all the same for your help :)
这篇关于如何自动采取无pressing上imagepickercontroller的phototaken按钮的图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文