How to save set of images to photo gallery in iphone app - iphone

I have to save some set of images to photo gallery in one button action.
for (j=85; j<100; j++)
{
UIImage *saveImage=[UIImage imageNamed:[NSString stringWithFormat:#"%d.png",j]];
UIImageWriteToSavedPhotosAlbum(saveImage,self,nil,nil);
}
I use the above code.image name starts with 85.png and ends with 100.png.It saves 4 or 5 images afterthat it shows some lines in output window as follows
-[NSKeyedUnarchiver initForReadingWithData:]: data is NULL
could anyone fix this problem?

Call Your Save method after some time delay. The image takes sometime to save in photo gallery. And when you save multiple images continuously then processing overwrites and method of saving image doesn't work.
So, delay at least 0.5 second for each image. I used this in my case see below method...
first declare
NSInteger frameCount;
NSTimer pauseTimer;
globally. and make a method name
-(void)startTimer;
now on your save button click call this method
-(void)yourSaveButtonClick:(id)Sender
{
[self startTimer];
}
-(void)startTimer
{
frameCount = 85;
pauseTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:#selector(myFunctionForSaveToPhoneLibrary) userInfo:nil repeats:YES];
}
-(void)myFunctionForSaveToPhoneLibrary
{
UIImage *saveImage=[UIImage imageNamed:[NSString stringWithFormat:#"%d.png",frameCount]];
UIImageWriteToSavedPhotosAlbum(saveImage,self,nil,nil);
frameCount++;
if(frameCount>=100)
{
[pauseTimer invalidate];
NSLog(#"Images are saved successfully");
}
}
it will Work ..... Thank You!!

Related

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...

Boost-button delay

I am making a game with a boost button. Of course, just leaving it as enabled would allow the player to tap it constantly. So, I need a 20 second delay before it is possible to push the button again. Also, would it be possible to show this progression on the button, preferably on the button itself?
In the future please try to show what you have tried to solve your problem. However, since you are new I'm going to let it slide once!
This code uses a NSTimer that is called once per second. It will fire what ever code you specify for "Boost". It will also disable user interaction on your button until it has been 20 seconds from when the button was pressed at which point it will allow the user to press the button again, and finally, this code displays how many seconds remain until "Boost" can be used again on the titleLabel property of your button.
- (IBAction)buttonPressed:(id)sender
{
myTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:#selector(activateBoost) userInfo:nil repeats:YES];
}
- (void)activateBoost
{
if (myButton.userInteractionEnabled == YES) {
//Put your Boost code here!
}
if ([myButton.titleLabel.text intValue] == 0) {
[myTimer invalidate];
[myButton setTitle:#"20" forState:UIControlStateNormal];
myButton.userInteractionEnabled = YES;
}else{
myButton.userInteractionEnabled = NO;
int currentTime = [myButton.titleLabel.text intValue];
int newTime = currentTime - 1;
myButton.titleLabel.text = [NSString stringWithFormat:#"%d",newTime];
}
}
In order for the above code to work, you will need the declare a NSTimer named "myTimer" and a UIButton "myButton". You will also need to set the buttons initial text to "20".

Image is already being captured or camera not yet ready

I am calling this takePicture function 5 times because i neeed to take 5 picture on on click(Burst Mode)
for(count=0;count<5;count++)
{
[picker takePicture];
[NSThread sleepForTimeInterval:0.5];
[[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode beforeDate: [NSDate date]];
}
I am getting this error UIImagePickerController: ignoring request to take picture; image is already being captured or camera not yet ready.
Not sure but i think camera not yet ready ... Because you are trying to capture images continuously.... I think you will have to delay for few seconds before call take picture method again..... Dont do it in for loop i would like to suggest you please use NSTimer instead of looping.
something like this -
Declare
-(void)startTimer;
and
int count;
in your .h class then see below code -
-(void)yourTakePictureButtonClick:(id)sender
{
[self startTimer];
}
-(void)startTimer
{
count = 0;
yourTimer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:#selector(myFunctionForClickImage) userInfo:nil repeats:YES];
}
-(void)myFunctionForClickImage
{
[picker takePicture];
count ++;
if (count < 5)
{
[yourTimer invalidate];
}
}
Hi H2SO4 (Nice Name han)
The most probable reason seems to be the absence of the required key in your info.plist file. You will need to configure UIRequiredDeviceCapabilities. Also, you must implement the delegate object. For details, have a look at
http://developer.apple.com/library/ios/#documentation/AudioVideo/Conceptual/CameraAndPhotoLib_TopicsForIOS/Articles/TakingPicturesAndMovies.html#//apple_ref/doc/uid/TP40010406.
HTH,
Another thing you should release your resources in every call inside loop.
You can delay with following.
[picker performSelector:#selector(takePicture) withObject:nil afterDelay:2.0];
For more you can visit...
http://highoncoding.com/Articles/856_Building_Instagram_for_the_iPhone_Part_2.aspx

Fetching image From Animating UIImageView

I'm using animation method of for implementing slide show in UIimageView as:
mainSlideShowImageView.animationImages=images;
mainSlideShowImageView.animationDuration = 75.00;
mainSlideShowImageView.animationRepeatCount = 0; //infinite
[mainSlideShowImageView startAnimating];
Now, what I want is to know which image is currently on image view screen.
How can I do so?
If it is not possible please tell that too.
Edit: 'images' here is array of UIImage.
AFAIK, there is no method which returns imageview's current image , however I have created a workaround for this....
array= [NSArray arrayWithObjects:[UIImage imageNamed:#"1.jpg"],[UIImage imageNamed:#"2.jpg"],[UIImage imageNamed:#"3.jpg"],[UIImage imageNamed:#"4.jpg"],[UIImage imageNamed:#"5.jpg"],nil];
mainSlideShowImageView.animationImages= array;
mainSlideShowImageView.animationDuration=15.0;
i=0;
timer = [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:#selector(increase) userInfo:nil repeats:YES];
[mainSlideShowImageView startAnimating];
-(void)increase
{
i++;
if (i>4) {
i=0;
}
}
-(void)getimage
{
UIImage* im = [array objectAtIndex:i];
// im is the current image of imageview
}
I have taken 5 images here and animation duration of 15 , that means image will change at every 3 seconds, so I have kept timer to fire at every 3 seconds ... and since array contains 5 images ... so if 'i' goes beyond 4 I have put it back to 0 in method increase

what method that is called when showing video preview in UIImagepickercontroller delegate in iphone

hello all I am working an app that automatically records a video. its does not showing preview of a video since I hidden the Cameracontrols . I want to know the method that calling the preview view..
Could anyone help me..
Thanks
Update
UIImagePickerController *vpicker; // in .h
// place the below code whr u want to satrt video
vpicker=[[UIImagePickerController alloc]init];
vpicker.delegate=self;
vpicker.sourceType=UIImagePickerControllerSourceTypeCamera;
vpicker.mediaTypes=[NSArray arrayWithObject:(NSString *)kUTTypeMovie];
vpicker.showsCameraControls=NO;
vpicker.cameraCaptureMode=UIImagePickerControllerCameraCaptureModeVideo;
BOOL test=[vpicker startVideoCapture];
NSLog(#"test value %d",test);
if(test)
{
NSLog(#"vedio started");
[NSTimer scheduledTimerWithTimeInterval:10.0f target:self selector:#selector(stop) userInfo:nil repeats:NO];
}
else
{
NSLog(#"sorry vedio not started to stop it ...");
}
// in stop method
[vpicker stopVideoCapture];
vpicker.showsCameraControls=YES;
MPMoviePlayerController is use to show video, not UIImagePickerViewController