如何从iPhone图片库浏览图片?

时间:2012-01-04 12:50:23

标签: iphone ios xcode image

我是ios开发的新手。我正在做一个照片裁剪应用程序。

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

如何浏览图像?。

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

iPhone中是否有可用的控件,如asp:FileUpload?

提前致谢。

2 个答案:

答案 0 :(得分: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;
}

从stackoverflow获取此代码,没有保存URL,抱歉。

答案 1 :(得分:0)

如果您运行的是非越狱手机,则无法使用整个文件系统。也没有文件系统浏览器控件(出于同样的原因),但是,您可以浏览用户的照片库,甚至可以使用UIImagePickerController与相机拍照。文档:http://developer.apple.com/library/ios/#documentation/uikit/reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html