我使用了代码
-(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];
}
}
我在这里使用故事板时遇到问题。我在情节提要中有多个视图控制器。我在第一个视图控制器上有相机按钮(用户可以在应用程序中拍照)。但是,我想将用户在第一个视图控制器中拍摄的照片数据自动传递给另一个视图控制器,以便用户可以裁剪它,然后将其保存到“目录或其他东西”中(尚未决定)。
更新我现在有四个错误,目前说 http://tinypic.com/view.php?pic=15q6y3b&s=5 点击图片它会更大