An1Ba7
An1Ba7

Reputation: 355

Application crashing in the imagePickerController:didFinishPickingMediaWithInfo method inside UIImagePickerController

I am a beginner in iOS development, I tried to make an application to select an image from the UIImagePickerController which is displayed inside a UIImageView object. The problem I am facing is inside this method

-(void)imagePickerController:(UIImagePickerController*)Picker didFinishPickingMediaWithInfo:(NSDictionary*)info
{
    NSLog(@"Inside dismiss modal view delegate 2");
    UIImage * image = [info objectForKey:UIImagePickerControllerOriginalImage];
    selectedImage.image = [image retain];
    NSLog(@"Inside the did pickerController method");
}

When I select an image from the UIImagePickerController, the image gets selected but the application crashes. I tried debugging, and the first NSLog statement gets displayed on the console, but the 2nd one does not get displayed.

I am trying to load an image from the Photos library inside the simulator. I am using XCode 3.2.5 and the simulator is 4.2. This might men the error is there in between the two NSLog statements. But, I have tried my best to find out the error, but without any success. Can you please help me out.

Upvotes: 1

Views: 1412

Answers (1)

Hector
Hector

Reputation: 3907

NSData *dataImage = UIImageJPEGRepresentation([info objectForKey:@"UIImagePickerControllerOriginalImage"],1);
imgPicture.image = [[UIImage alloc] initWithData:dataImage];
[picker dismissModalViewControllerAnimated:YES];

Put this code in method

Upvotes: 3

Related Questions