7

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.

Arun
  • 3,478
  • 8
  • 33
  • 46

2 Answers2

10

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.

Paul Cezanne
  • 8,629
  • 7
  • 59
  • 90
  • 1
    Thankx alot. It works. It really helped me alot. I was searching for this from the past two days. Thankx – Arun Jan 04 '12 at 13:07
0

The whole file system is not available, if you're running a non-jailbroken phone. Neither are there filesystem browser controls (for the same reason), However, you can browse the user's photo library, or even take a photo with the camera using UIImagePickerController. Docs: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html