PDA

View Full Version : Taking more then one picture




CNuland
Jul 28, 2010, 11:49 AM
I'm trying to allow the users of my application to take more then one picture without having to press the "take picture" button on my application again. So instead of



"take picture" -> capture -> use -> "take picture" -> capture



it would be,

"take picture" -> capture -> use -> capture -> use -> capture -> use



Here's the code I have right now,


- (void) imagePickerController: (UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *image;
NSURL *mediaUrl;
mediaUrl = (NSURL *)[info valueForKey:UIImagePickerControllerMediaURL];

if(mediaUrl == nil){
image = (UIImage *) [info valueForKey:UIImagePickerControllerEditedImage];
if(image == nil){
image = (UIImage *) [info valueForKey:UIImagePickerControllerOriginalImage];
//[image retain];
AnnotatedImage *a = [[AnnotatedImage alloc] initWithName:@"Picture" description:@"mmmm"];
NSData *reducedImage = UIImageJPEGRepresentation(image, .5);
[reducedImage retain];
// [a setImage: image];
[a setImage2: reducedImage];

// NSData *pngImage = UIImagePNGRepresentation(image);
UIImage *myThumbNail = [[UIImage alloc] initWithData:reducedImage];

// begin an image context that will essentially "hold" our new image
UIGraphicsBeginImageContext(CGSizeMake(150.0,150.0));
// now redraw our image in a smaller rectangle.
[myThumbNail drawInRect:CGRectMake(0.0, 0.0, 150.0, 150.0)];
//[myThumbNail release];
// make a "copy" of the image from the current context
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[a setThumbImage:newImage];
[myThumbNail release];


[images addObject:a];
[a release];
}
else{
imageView.image = image;
}

}
else {
//<#statements#>
}
[picker dismissModalViewControllerAnimated:YES];
[self btnLoadImage];
}



The method [self btnLoadImage]; at the end is calling the same method that happens whe "take picture" button is pressed. However, the camera does not come back up. I also tried to reload the camera from within the method - (void) imagePickerController: and the application crashed once I tried it. Thanks for any help you can provide.



PhoneyDeveloper
Jul 28, 2010, 12:31 PM
You probably need a delay between when one view controller goes away and another can be pushed. You probably need to push the camera view again in viewWillAppear or viewDidAppear of the underlying view controller.

CNuland
Jul 28, 2010, 01:15 PM
When I add a ViewDidLoad or ViewWillLoad to the ViewController it isn't called after the camera returns to the view =\.

- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSLog(@"works");
}

Is there another solution? or possible another way to call for a new imagePicker to be created?

dejo
Jul 28, 2010, 02:07 PM
When I add a ViewDidLoad or ViewWillLoad to the ViewController it isn't called after the camera returns to the view =\.

- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSLog(@"works");
}
Okay, but is your viewWillAppear: being called?

P.S. The other method is viewDidLoad (and there is no viewWillLoad). Objective-C is case-sensitive. Precision is important.

CNuland
Jul 28, 2010, 02:32 PM
Alright, I got viewWillAppear working now, but it still work bring up the camera when I call it.

- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSLog(@"works");
[self btnLoadImage];
}


All btnLoadImage does is create the imagePicker and set it to use the camera (it works when it's called by the button linked with it). I even tried creating the imagepicker inside viewWillAppear and it still doesn't work.

dejo
Jul 28, 2010, 02:42 PM
What's the code for btnLoadImage look like?

CNuland
Jul 28, 2010, 02:45 PM
Check is just making sure the user has created an account with my app before they take pictures. I believe it's loading fine, for some reason it just doesn't make a new imagePicker when it's called (yet it works if the user presses the take picture button again)

- (IBAction) btnLoadImage {
BOOL check = [self checkAccount];
if(check) {

imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:imagePicker animated:YES];
}
}

dejo
Jul 28, 2010, 03:01 PM
First, is btnLoadImage getting executed from within viewWillAppear? Setting a breakpoint and stepping through and into btnLoadImage, especially, can verify this.

Second, how is imagePicker defined and set?

robbieduncan
Jul 28, 2010, 04:13 PM
Take a look at the AVFoundation framework additions in 4.0 (and even better 4.1 if you have access to that). You can take pictures entirely under your control and without using the standard picker controller.

CNuland
Aug 2, 2010, 01:12 PM
First, is btnLoadImage getting executed from within viewWillAppear? Setting a breakpoint and stepping through and into btnLoadImage, especially, can verify this.

Second, how is imagePicker defined and set?

Dejo, yes, I put in a log statement and it was being called when the view returned back to the view. I've tried tons of ways around this.. I even had NSThread delay a couple seconds to see if for some reason there was a time delay in the camera being reset. For some reason it seems apple wont let you load another image picker until the app has returned to the view it was created on.

I would rather avoid using AVFoundation right now. I don't know much about that framework and would rather not write my own camera class for something as simple as this.