如何以编程方式查看相册中的照片?

时间:2012-10-03 12:39:10

标签: iphone ios xcode uiimagepickercontroller

我使用以下代码从相册中获取图片。

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

但我没有收到设备的任何回复。 我已经完成了所有的答案,但它不适合我。 任何人都可以告诉我如何从相册中获取图像。

1 个答案:

答案 0 :(得分:0)

release方法中删除didFinishPickingMediaWithInfo语句。把它写成

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