Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting image from UIImagePickerController

I want to get the image frm imagepickercontroller.But my code doesn't have any effect Here is the code..

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [picker dismissModalViewControllerAnimated:YES];
    imageview.image = [UIImage imageNamed:[info objectForKey:@"UIImagePickerControllerOriginalImage"]];
like image 703
varth_FD Avatar asked Oct 14 '11 10:10

varth_FD


People also ask

How can you prevent a pick GIF image in UIImagePickerController?

You can try setting UIImagePickerController. mediaTypes explicitly for the types you want. By default it is set to [kUTTypeImage] which covers all image types - jpeg, png, gif, heif and more...

How do I use image picker in Swift?

storyboard file and add two elements inside the view controller. The first one is a button, which will show up an image picker modal whenever it gets pressed. The second one is an image view. I'm going to put a placeholder image at first, but once the user selected an image, we'll display that image to that view.


2 Answers

You can try this code to access an Image returned from the picker

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

    [picker dismissModalViewControllerAnimated:YES];

    UIImage* originalImage = nil;
    originalImage = [info objectForKey:UIImagePickerControllerEditedImage];
    if(originalImage==nil)
    {
        originalImage = [info objectForKey:UIImagePickerControllerOriginalImage];
    }
    if(originalImage==nil)
    {
        originalImage = [info objectForKey:UIImagePickerControllerCropRect];
    }
  //At this point you have the selected image in originalImage
    [self saveImageToDocumentDirectory:originalImage];
}
like image 157
Rahul Sharma Avatar answered Oct 22 '22 11:10

Rahul Sharma


Try

imageview.image = (UIImage*) [info objectForKey:UIImagePickerControllerOriginalImage];
like image 44
Philipp Schlösser Avatar answered Oct 22 '22 10:10

Philipp Schlösser