0

I am developing an application that uses the camera. I am using browsing option to browse the photos from the gallery. I am also presenting the option to take a photo if required. For getting the selected photo while browsing I have implemented UIImagePickerControllerDelegate method:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo 
 {
      [self dismissModalViewControllerAnimated:YES];
      imageView.image = img;    
  }

I am getting the selected image in this method. But how can I get the image captured by the camera in my imageView without saving it into the gallery? Will I get the image in the same method?

Rob
  • 415,655
  • 72
  • 787
  • 1,044
V-Xtreme
  • 7,230
  • 9
  • 39
  • 79

3 Answers3

2

You are using imagePickerController:didFinishPickingImage:editingInfo:. This is deprecated in ios 3.0. Refer UIImagePickerControllerDelegate also refer this link why not to use deprecated methods.

you have to use imagePickerController:didFinishPickingMediaWithInfo: as follows:

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

{
     yourImageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
     [self dismissModalViewControllerAnimated:YES];
}

this will work for both of your camera and Photo gallery. You also don't need to save image captured using camera. You can directly assign it to your image view as this code is doing.

Hope this helps you.

Community
  • 1
  • 1
Kapil Choubisa
  • 5,152
  • 9
  • 65
  • 100
1

This is simple, you just need to pass the UIImage straight into your UIImageView

 yourImageView.image = img;
Kapil Choubisa
  • 5,152
  • 9
  • 65
  • 100
Pork 'n' Bunny
  • 6,740
  • 5
  • 25
  • 32
0

Please try this:

- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSLog(@"Media Info: %@", info);
NSString *mediaType = [info valueForKey:UIImagePickerControllerMediaType];
if([mediaType isEqualToString:(NSString*)kUTTypeImage]) {
    UIImage *photoTaken = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    //Save Photo to library only if it wasnt already saved i.e. its just been taken
    if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) {
        yourImageView.image = img }
}
[self dismissModalViewControllerAnimated:YES];
}
Hemant Dixit
  • 1,145
  • 8
  • 12