Cherr Skees
Cherr Skees

Reputation: 1518

UIImagepickercontroller Not Selecting Image

I had this working in an old code that I didn’t end up using... now I’m trying it again and it isn’t working. I”m not sure what is wrong. I’d like the user to select an image and then have it available in imageView1 for display. I appreciate the assistance.

- (IBAction)pushPick 
{
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate =self;
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    [self presentModalViewController:picker animated:YES];
    //[picker release];
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:   (UIImage *)image editingInfo:(NSDictionary *)editingInfo {
    [picker.parentViewController dismissModalViewControllerAnimated:YES];
    imageView1.image = image;
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
    [picker.parentViewController dismissModalViewControllerAnimated:YES];
}

Upvotes: 1

Views: 1379

Answers (2)

Alex L
Alex L

Reputation: 8449

Try

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{  
    UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    imageView1.image = image;
    [picker release];
    [self dismissModalViewControllerAnimated:YES]; 

}

And make sure the view controller responds to UIImagePickerControllerDelegate.

imagePickerController:didFinishPickingImage:editingInfo: was deprecated in iOS 3.0.

Upvotes: 6

fargo
fargo

Reputation: 11

This is how I do this:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

{ bgImage.image = [info objectForKey:UIImagePickerControllerEditedImage];

UIGraphicsBeginImageContextWithOptions(CGSizeMake(128, 128), YES, 1.0);

[bgImage.image drawInRect:CGRectMake(0,0,128,128)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

NSData *imageData = UIImageJPEGRepresentation(newImage, 1.0);
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString *documentsFolder = [path objectAtIndex:0];

NSString *tmpPathToFile = [[NSString alloc] initWithString:[NSString stringWithFormat:@"%@/specificImagedName.jpg", documentsFolder]];

if([imageData writeToFile:tmpPathToFile atomically:YES]){
    //NSLog(@"write succesful");
}
///////////////////////////////////////////

[po dismissPopoverAnimated:YES];
[picker release];
[tmpPathToFile release];}

it generates a jpg file to the documents folder of your app. Hope it helps..

Upvotes: 0

Related Questions