Edit image after taking a picture

19,612

there's a way don't change your code much:

- (IBAction)takePicture:(id)sender {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
    [imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
} else {
    [imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
}

[imagePicker setAllowsEditing:YES];
[imagePicker setDelegate:self];

//place image picker on the screen
[self presentViewController:imagePicker animated:YES completion:nil];
}

If you want to use the image that after editing, please change "UIImagePickerControllerOriginalImage" to "UIImagePickerControllerEditedImage", that's it!

Share:
19,612
hakimo
Author by

hakimo

Updated on August 05, 2022

Comments

  • hakimo
    hakimo over 1 year

    I'm currently making an iphone app where the user takes a photo or select it from an album, then an overlay is placed over the image. The user can then scale, rotate and save the image. Currently, I can take pictures, or choose one for the album. As for the overlay, I just used UIImageView and placed it on top of the hierarchy in Interface builder. For the camera, I'm using this code:

    -(IBAction)getPhoto:(id)sender  {
    
    // Create an image picker controller
    UIImagePickerController * imagePicker = [[UIImagePickerController alloc] init];
    
    
    if((UIButton *) sender == choosePhotoBtn)   {
        // Set source to photo albums
        imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    }
    
    else    {
        // Set source to camera
        imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
        imagePicker.showsCameraControls = YES;
    }
    
    // Delegate is self
    imagePicker.delegate = self;
    
        // Allow editing of image
        imagePicker.allowsEditing = YES;
    
        // Show image picker
        [self presentModalViewController:imagePicker animated: YES];
    }
    
    -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info   {
    // Dismiss modalviewcontroller
    [picker dismissModalViewControllerAnimated:YES];
    
    // Displaying image to the imageView
    imageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    
    // Access the uncropped image from info dictionary
    UIImage * image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    
    
    // Save Image
    UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
    
    [picker release];
    }
    

    The problem I'm having right now, is editing the photo after it's being taken. How do I customise the camera to behave like this?:

    1. Choose either use the camera or getting the photo from the album

    2. Once chosen, the overlay image will change to a one where I've put a "circle" in the face, and the photo will be underneath like a mask. This view will also be able to edit in full screen. You can rotate, scale and move the image until you click done.

    I've read this part in the manual but I can't seem to understand how to use it. http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html

    Hope someone can point me to the right direction.

    Thanks very much. -Hakimo

  • hakimo
    hakimo almost 13 years
    Thanks for the reply Xcoder. I've never used action sheets before so I will give it a try. Is there a difference between using action sheets and the one I wrote? I can get pictures from albums and take photos but I'm not to sure how to customise the edit page.
  • hakimo
    hakimo almost 13 years
    Now I see what action sheets are. It's almost like a UIAlertView. I might use this for saving the image to album prompt. Thanks again.
  • inherithandle
    inherithandle over 8 years
    Where OP is using UIImagePickerControllerOriginalImage or UIImagePickerControllerEditedImage? I don't understand you.
  • Vito Royeca
    Vito Royeca over 8 years
    @inherithandle OP is referring to imagePickerController:didFinishPickingMediaWithInfo: method of UIImagePickerControllerDelegate. The info parameter contains an NSDictionary that contains the Editing Information Keys like UIImagePickerControllerOriginalImage and UIImagePickerControllerEditedImage