2012-01-04 67 views
7

我是ios开发新手。我正在做一个照片裁剪应用程序。如何从iPhone图片库浏览图片?

我想通过点击浏览按钮(我在我的应用程序中添加)来浏览iPhone图片库中的图像,并将其加载到我放置在视图中的UIImageview中。

如何浏览图片?

是否可以浏览完整的手机内存? (就像asp:FileUpload)。

iPhone中是否有任何控件可以像asp一样使用:FileUpload?

在此先感谢。

回答

9

超级容易做!

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

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

- (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; 
} 

得到了计算器这个代码,没有保存URL,对不起。

+1

Thankx alot。有用。它真的帮了我很多。我过去两天正在寻找这个。 Thankx – Arun 2012-01-04 13:07:18