Wie speichern Sie ein UIImagePickerController
-Kamerabild, damit ich es an die CreateViewController
-Szene UIImageView
senden kann?
HomeViewController
(Szene 1) hat einen Button, der UIImagePickerController
lädt und mit einem Bild aus der Kamera zurückkehrt. CreateViewController
(Szene 2) hat eine leere UIImageView
.
HomeViewController.h
#import "CreateViewController.h"
@interface HomeViewController : UIViewController
@property (strong, nonatomic) UIImagePickerController *imagePicker;
@property(nonatomic, retain) UIImage *myImage;
- (IBAction)cameraImage:(id)sender;
HomeViewController.m
@implementation HomeViewController
@synthesize imagePicker, myImage;
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ( [segue.identifier isEqualToString:@"create"]) {
CreateViewController *cvc = [segue destinationViewController];
UIImage *image = myImage;
cvc.myImage = image;
}
}
//Kamera-Button-Aktion
- (IBAction)cameraImage:(id)sender{
//UIImagePickerController Speicherplatz
imagePicker = [[UIImagePickerController alloc]init];
//Den Delegaten setzen
imagePicker.delegate = self;
//Der sourceType setzen
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
//Image Picker UI anzeigen
[self presentViewController:imagePicker animated:YES completion:^{}];
}
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo: (NSDictionary *)info {
self.myImage = [info objectForKey:UIImagePickerControllerOriginalImage];
[self dismissViewControllerAnimated:YES completion:^{}];
[self performSegueWithIdentifier:@"create" sender:self];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self dismissViewControllerAnimated:YES completion:^{}];
}
CreateViewController.h
@property (strong, nonatomic) IBOutlet UIImageView *bgImage;
@property(nonatomic, retain) UIImage *myImage;
CreateViewController.m
@implementation CreateViewController
@synthesize bgImage, myImage;
- (void)viewDidLoad
{
[super viewDidLoad];
UIImage *image = myImage;
[bgImage setImage:image];
}
Sample-Code hier herunterladen; http://code-blind.com/ios6-camera-picture-to-another-scenes-uiimageview/