Taking more then one picture

Discussion in 'iOS Programming' started by CNuland, Jul 28, 2010.

  1. macrumors newbie

    Joined:
    Jun 17, 2010
    #1
    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,

    Code:
    - (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.
     
  2. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #2
    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.
     
  3. thread starter macrumors newbie

    Joined:
    Jun 17, 2010
    #3
    When I add a ViewDidLoad or ViewWillLoad to the ViewController it isn't called after the camera returns to the view =\.
    Code:
    - (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?
     
  4. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    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.
     
  5. thread starter macrumors newbie

    Joined:
    Jun 17, 2010
    #5
    Alright, I got viewWillAppear working now, but it still work bring up the camera when I call it.
    Code:
    - (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.
     
  6. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
  7. thread starter macrumors newbie

    Joined:
    Jun 17, 2010
    #7
    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)

    Code:
    - (IBAction) btnLoadImage {
    	BOOL check = [self checkAccount];
    	if(check) {
    		
    		imagePicker.delegate = self;
    		imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
    		[self presentModalViewController:imagePicker animated:YES]; 
    	}
    }
     
  8. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #8
    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?
     
  9. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #9
    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.
     
  10. thread starter macrumors newbie

    Joined:
    Jun 17, 2010
    #10
    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.
     

Share This Page