I used the code
-(IBAction)TakePhoto {
picker = [[UIImagePickerController alloc]init];
picker.delegate = self;
[picker setSourceType:UIImagePickerControllerSourceTypeCamera];
[self presentViewController:picker animated:YES completion:nil];
[self performSegueWithIdentifier:@"CropImage" sender:sender];
}
- (void) imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info {
//obtaining saving path
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *imagePath = [documentsDirectory stringByAppendingPathComponent:@"latest_photo.png"];
//extracting image from the picker and saving it
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:@"public.image"]){
UIImage *editedImage = [info objectForKey:UIImagePickerControllerEditedImage];
NSData *webData = UIImagePNGRepresentation(editedImage);
[webData writeToFile:imagePath atomically:YES];
}
}
- (void)imagePickerControllerDidCancel :(UIImagePickerController *)picker {
[self dismissViewControllerAnimated:YES completion:NULL];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:@"CropImage"])
{
CropImageViewController *cropImageViewController = segue.destinationViewController;
cropImageViewController.theImage = yourImage;
// Similar to [segue.destinationViewController setTheImage:yourImage];
}
}
I have a problem here using the storyboard. I have multiple view controllers in the storyboard. I have the camera button (which the user can take the photo in app) on the first view controller. However I want to pass the data of the photo that the user took in the first view controller to another view controller automatically so that the user can crop it and then save it into a "directory or something"(did not decide yet).
update I am having now four errors currently saying http://tinypic.com/view.php?pic=15q6y3b&s=5 Click the image it will be bigger