-1

我正在尝试将上传图像功能添加到我的 iphone 应用程序,这样当用户访问他们的主页时,他们可以从手机上传照片,下次他们访问该照片时将显示该照片。

我有的 :

//Button action to add upload function

-(IBAction)upload:(id)sender
{
    UIImagePickerController *pics = [[UIImagePickerController alloc] init];
    pics.delegate = self;
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
    {
        pics.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    }
    [self presentViewController:pics animated:YES completion:NULL];
    [pics release];
}

- (void)imagePickerController:(UIImagePickerController *) Picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    // replace image holder with chosen image
    _imageView1.image=UIImagePickerControllerSourceTypePhotoLibrary;
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *) Picker
{
    [self dismissViewControllerAnimated:YES completion:NULL];
}
4

2 回答 2

1

UIImagePickerControllerSourceTypePhotoLibrary引用整个照片库,让用户选择哪个相册。

在你的didFinishPickingMediaWithInfo方法中,使用

_imageView1.image = [info objectForKey:UIImagePickerControllerOriginalImage];

可选:如何访问设备的照片库?...我基本上会使用AssetsLibrary.framework来完成。它为我提供了更多使用它的选择。

查看github中提供的此示例代码。它提供了选择多个图像的能力。它与 UIImagePickerController 一样易于设置,并且可以在纵向和横向方向上工作。它需要添加 AssetsLibrary.framework。此代码使用 ARC。

于 2013-09-24T09:12:03.917 回答
0

尝试这个,

- (void)imagePickerController:(UIImagePickerController *) Picker

    didFinishPickingMediaWithInfo:(NSDictionary *)info {

//replace image holder with chosen image 

 UIImage *pickedImage = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
[_imageView1 setImage: pickedImage];

}
于 2013-09-24T09:06:51.510 回答