2

I have a UIImageView outlet in my page. I want that to be filled with an image of user's choice. So on click of a button underneath, user can select image from library/camera. Till here all s fine. However, once the user selects an image, say from the photo library, it does not display it on the UIIMageView. The following is the code

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
[picker dismissModalViewControllerAnimated:YES];
imageView1.image = [info objectForKey:@"UIImagePickerControllerEditImage"];
NSLog(@"Image being added to the view");

}

The NSLog in console confirms the function call. Any comments on why the image is not being displayed?

Andy
  • 1,080
  • 5
  • 20
  • 35
  • maybe imageView1 is nil? – MarkPowell May 09 '11 at 20:21
  • but y is it still nil if i am setting the imagView1.image to the image from the picker? – Andy May 09 '11 at 22:04
  • Not imageView1.image, imageView1. Did you connect in via an IBOutlet in Interface Builder or create it programmatically? – MarkPowell May 10 '11 at 01:18
  • via Interface Builder. Do you mean i should instantiate imageView1 in the .m file? I have defined it in the .h file and synthezise it in the corresponding .m file – Andy May 10 '11 at 09:31

3 Answers3

0

I think you did not give the connection to the outlet. If u have given the connection , Implement this Delegate method. In method body use the input parameter "image" like:

  • (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo

{

     myImageView.image = image;

}

Thats all.

YSR fan
  • 705
  • 6
  • 11
0

Your method should be look like below:

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

{

[picker dismissModalViewControllerAnimated:YES];

imageView1.image = [info objectForKey:UIImagePickerControllerOriginalImage];
}
Bart
  • 19,692
  • 7
  • 68
  • 77
Gajendra K Chauhan
  • 3,387
  • 7
  • 40
  • 55
0

The Dictonary info consist of {

UIImagePickerControllerMediaType = "public.image";
UIImagePickerControllerOriginalImage = "<UIImage: 0x7c73290>";
UIImagePickerControllerReferenceURL = "assets-library://asset/asset.JPG?id=70252FFF-1654-49A5-9FEE-5FF19454AE3F&ext=JPG";

}

From this you can take image by using key;

saravana
  • 544
  • 1
  • 7
  • 26