Capture frames with time delay - iPhone camera - iphone

I'm trying to write some objective-c code that allows capture of frames through the iPhone camera, after a specific time delay. Any examples I have found online have captured the 'present' frame input by the camera (i.e. a realtime frame capture). I am looking for a less real time frame capture - a way to capture frames with a specific time delay. Any ideas?

I would use NSTimer.
It would allow you to use the code that captures the current frame, and it would get called after a delay.
You can create a non-repeating timer like this: timer = [NSTimer scheduledTimerWithTimerInterval:delay target:self selector:#selector(capture) userInfo:nil repeats:NO]; where delay is the specific time delay and capture is a method that contains the code from an example that captures the present frame.

Use following code.....
//call method according to your delay that you need.....
float yourdelay;
yourdelay = 0.7;
[self performSelector:#selector(captureView) withObject:nil afterDelay:yourdelay];
// or set time for calling method....
[NSTimer scheduledTimerWithTimeInterval:0.02 target: self selector:#selector(captureView) userInfo:nil repeats:NO];
///or you can call method directly when you need..
[self captureView];
////Here the code for capture real time image.
- (void)captureView {
UIGraphicsBeginImageContext(mapView.frame.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
flickerImaveView.image=viewImage;
}
Hope this will help you....

Related

How to prevent UIImage from continually replaying an animation

I am making a game and currently my "player" is animating as I've implemented (which is wrong at the moment) and it continually runs the animation from start to start because it always restarts from the beginning when the function is called. What is the best way to prevent this and let the animation run all the way through? Here is the code I'm using at the moment:
- (void) startAnimatingLeft
{
NSArray *images = [NSArray arrayWithObjects:img9,img10,img11,img12,img13,img14,img15,img16, nil];
[imageView setAnimationImages:images];
[imageView startAnimating];
animateTimer = [NSTimer scheduledTimerWithTimeInterval:0.6 target:self selector:#selector(nothingMovingLeft) userInfo:nil repeats:NO];
}
From UIImage documentation:
startAnimating
This method always starts the animation from the first image in the list.
So you shouldn't call this method if the image is already animating. You can call isAnimating method to check if image is animating.

How to take and save 20 photo in one second using objective c

I am creating one photo capture app in which user can take up to 20 photo in one second.
I have already try the AVCam Sample code of apple but it is don't allow to take still Image at 20 FPS.
Is there any other way to take photo at this rate.
see this Demo..Photo Picker
in this demo just check or refer these two classes..
MyViewController.m and
OverlayViewController.m
in OverlayViewController.m class in timedTakePhoto method just set timer with your requirement like bellow..
- (IBAction)timedTakePhoto:(id)sender
{
// these controls can't be used until the photo has been taken
self.cancelButton.enabled = NO;
self.takePictureButton.enabled = NO;
self.timedButton.enabled = NO;
self.startStopButton.enabled = NO;
if (self.cameraTimer != nil)
[self.cameraTimer invalidate];
_cameraTimer = [NSTimer scheduledTimerWithTimeInterval:0.03
target:self
selector:#selector(timedPhotoFire:)
userInfo:[NSNumber numberWithInt:kOneShot]
repeats:YES];
// set time with your requirement above
// start the timer to sound off a tick every 1 second (sound effect before a timed picture is taken)
if (self.tickTimer != nil)
[self.tickTimer invalidate];
_tickTimer = [NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:#selector(tickFire:)
userInfo:nil
repeats:YES];
}
may you can get idea from this and also use this demo for your requirement..
i hope this help you...

Xcode NSTimer get position object every millisecond

I need to get the position of the _propArrow (UIImageView) every .1sec at all time and use a NSLog to verify in the method (void)runScheduledTask
but does not operate every .1 sec.
only indicates the start and end of the movement of the animation
This is my code:
- (void)viewDidLoad
{
[super viewDidLoad];
_propArrow.frame = CGRectMake(144, 291, 33, 71);
aTimer = [NSTimer scheduledTimerWithTimeInterval:.1 target:self selector:#selector(runScheduledTask) userInfo:nil repeats:YES];
}
- (void)runScheduledTask {
NSLog(#"Position: %#", NSStringFromCGRect(_propArrow.frame));
}
- (IBAction)fire:(id)sender {
[UIView animateWithDuration:1
delay:0
options:UIViewAnimationCurveEaseInOut
animations:^{
_propArrow.frame = CGRectMake(144, 0, 33, 71);
}
completion:^(BOOL finished){
}];
}
First, according to the NSTimer docs, that class has an effective resolution of about 50-100 ms. So using it to do anything at 1 ms intervals is bound to fail.
Second, even if NSTimer could handle 1 ms intervals, you're not even asking it to do that:
aTimer = [NSTimer scheduledTimerWithTimeInterval:.05...
Your code schedules the timer to run ever 0.05 s, which is to say every 50 ms.
Third, the screen doesn't update at anything close to 1 ms intervals, so the actual position of your image on the screen will change much less often than that.
So, what exactly are you trying to accomplish here? If you want to know where the object would be in the real world with continuous motion, you can calculate that for any point in time.
Because in most UIKit animated properties, the new value gets set immediately from the perspective of your code; it's the displayed value that actually animates. Reading animatable properties like UIView.frame should never give you an intermediate value (the main exception is UIScrollView which does its own thing for animated scrolling).
If you want "approximately what's being displayed on screen", you need to access the CoreAnimation "presentation layer":
#import <QuartzCore/CALayer.h>
- (void)runScheduledTask {
NSLog(#"Position: %#", NSStringFromCGRect(_propArrow.layer.presentationLayer.frame));
}
Also consider using CADisplayLink if you want a callback that runs every frame.

NSTimer firing instantly

I'm trying to develop a game and running into a small issue with NSTimer, once a sprite appear it has a certain amount on time in my scene before fading out.
double CALC_TIME = 5;
[NSTimer scheduledTimerWithTimeInterval:CALC_TIME target:self selector:#selector(hideSprite) userInfo:nil repeats:NO];
I want hideSprite to be called after 5 seconds, but instead it's called instantly(Or near instant).
A possible solution:
I know I could do this by setting the timer to repeat, and having a bool firstCall that is set first time and then the next interval the fading is done, the timer is invalidated but I don't think this is good practice
Like this:
bool firstCall = false;
-(void)hideSprite{
if(!firstCall){
firstCall = true
}else{
//fade out sprite
//Invalidate NSTimer
//firstCall = false;
}
}
Thanks for your help!
I suspect something else is calling hideSprite. The code you have written will cause the timer to wait for five seconds before calling the selector hideSprite.
Provide a different selector (write a new test method which just does an NSLog) to the timer and see what happens. This will tell you a) whether the timer is indeed immediately firing and b) if something else is calling hideSprite.
[NSTimer scheduledTimerWithTimeInterval:CALC_TIME target:self selector:#selector(testTimer) userInfo:nil repeats:NO];
-(void) testTimer { NSLog(#"Timer - and only the timer - called me."); }
-(void) hideSprite {
NSLog(#"I definitely wasn't called by the timer.");
}
Quite often it's easier to just use something like
[UIView animateWithDuration: 0 delay: 5 options:0 animations: nil completion:
^{
// fade sprite
}];
(not sure if animations can be nil, but you get the idea).
Consider initializing your timer using the initWithFireDate:interval:target:selector:userInfo:repeats method. Here is a more detailed look at NSTimer.

image change every a fixed time in iPhone

I have 4 images. I want to load image in first screen and change images after every 10 second. when we click any images than next screen come up.
please give me help i am new in iPhone.
Use NSTimer to trigger the image change. If the user taps an image and you want to stop the image rotation, you can invalidate the timer before switching to the next view.
You can try by creating a method that changes the image in the imageView and calling it using a NSTimer which repeatedly calls the method every 10 seconds.
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:#selector(changeImage) userInfo:nil repeats:YES];
- (void)changeImage {
// Change image here
}
HI Avinash,
I think you need below code...
******* IN VIEW DID LOAD
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:#selector(changeImage) userInfo:nil repeats:YES];
- (void)changeImage {
[self.imgview setImage:[UIImage imageNamed:#"test.png"]];
}
Thx