在iPhone中显示Gallery中的图像

Sha*_*hah 4 iphone uiimageview

我是iPhone的新手,现在是学习阶段的一天.实际上我想实现我读取存储在我的i​​Phone PHOTO Gallery中的图像,然后将其显示在我的应用程序上.

我在许多搜索引擎中搜索过但找不到任何东西.你们都是这里的专业人士.请指导我通过一些代码或一些教程.

非常感谢

Rob*_*bin 11

编辑

另请查看此问题/答案以及用于获取图像uiimagepickercontroller的方法,因为我之前提到的方法已弃用.

didFinishPickingMediaWithInfo返回零照片


查看文档http://developer.apple.com/library/ios/#documentation/uikit/reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html并查看此链接

http://iphone.zcentric.com/2008/08/28/using-a-uiimagepickercontroller/

它有相同的示例.

您可以使用这些方法在UIImageView对象中获取图像

- (void)selectPhotos
{
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    picker.delegate = self;
    [self presentViewController:picker animated:YES completion:nil];
    //Deprecated In IOS6[self presentModalViewController:picker animated:YES]; 
    [picker release];
}

- (void)imagePickerController:(UIImagePickerController *)picker
        didFinishPickingImage:(UIImage *)image
                  editingInfo:(NSDictionary *)editingInfo
{
    imageView.image = image;
    [[picker parentViewController] dismissModalViewControllerAnimated:YES];
}
Run Code Online (Sandbox Code Playgroud)

  • 不,你不能这样做,它不被iOS所允许. (2认同)

Sab*_*bby 5

您可以像这样访问iPhone图像库,然后从那里选择图像

if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
        {
            if (picker == nil) {
                picker = [[UIImagePickerController alloc] init];
                picker.allowsEditing = NO;

            }
            picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            picker.delegate = self;
            // Make camera view full screen:
            picker.wantsFullScreenLayout = YES;
            [self.navigationController presentModalViewController:picker animated:YES];
        }
Run Code Online (Sandbox Code Playgroud)

然后实现委托方法来获取图像......

- (void)imagePickerController:(UIImagePickerController *)picker1 didFinishPickingMediaWithInfo:(NSDictionary *)info
{ 

    cameraClickedImage=[info valueForKey:UIImagePickerControllerOriginalImage];
     UIImage *thumbImage = [cameraClickedImage imageByScalingAndCroppingForSize:CGSizeMake(320, 480)];
    clickedImageView.image =thumbImage;
    [picker1 dismissModalViewControllerAnimated:YES];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker1 {
    NSLog(@"Cap1");
    [picker1 dismissModalViewControllerAnimated:YES];
    [self.navigationController popViewControllerAnimated:NO];
}
Run Code Online (Sandbox Code Playgroud)

希望这会对你有所帮助..........干杯......