Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I browse a picture from iPhone picture library?

I am new in ios development. I am doing a photo cropper app.

I want to browse an image from the iPhone picture library by clicking browse button (that I added in my app) and load it to UIImageview that I placed in a view.

How can I browse the image ?.

Is it possible to browse the complete phone memory ? (Just like asp:FileUpload).

Is there any control available in iPhone to use just like asp:FileUpload ?

Thanks in advance.

like image 287
Arun Avatar asked Jan 04 '12 12:01

Arun


1 Answers

Super easy to do!

UIImagePickerController *imagePicker = [[UIImagePickerController     alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

[imagePicker setDelegate:self];
[self presentModalViewController:imagePicker animated:YES];

and

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{
    [picker dismissModalViewControllerAnimated:YES];
    [picker release];

    // Edited image works great (if you allowed editing)
    //myUIImageView.image = [info objectForKey:UIImagePickerControllerEditedImage];
    // AND the original image works great
    //myUIImageView.image = [info objectForKey:UIImagePickerControllerOriginalImage];
    // AND do whatever you want with it, (NSDictionary *)info is fine now
    //UIImage *myImage = [info objectForKey:UIImagePickerControllerEditedImage];

    UIImage *image =  [info objectForKey:UIImagePickerControllerOriginalImage];

    [customImageView setImage:image]; 

    customImageView.contentMode = UIViewContentModeScaleAspectFill;
}

got this code from stackoverflow, didn't save the URL, sorry.

like image 53
Paul Cezanne Avatar answered Oct 07 '22 00:10

Paul Cezanne