从iPhone相机卷中获取图像

从iPhone相机卷中获取图像,iphone,camera,photo,Iphone,Camera,Photo,我目前有一个UIImageView和一个UIImage。我如何允许用户从相机卷中选择一张照片 有,但我运气不好。这可能是因为我没有在Interface Builder中连接东西 我想要一些简单的东西,比如UIImage*image=[UIImage imageFromCameraRoll],但不幸的是,这是不可能的,至少我不这么认为。使用UIImagePickerController,查看Apple文档 选择源类型: @property (nonatomic) UIImagePickerCont

我目前有一个UIImageView和一个UIImage。我如何允许用户从相机卷中选择一张照片

有,但我运气不好。这可能是因为我没有在Interface Builder中连接东西

我想要一些简单的东西,比如UIImage*image=[UIImage imageFromCameraRoll],但不幸的是,这是不可能的,至少我不这么认为。

使用UIImagePickerController,查看Apple文档

选择源类型:

@property (nonatomic) UIImagePickerControllerSourceType sourceType
从那时起:

UIImagePickerControllerSourceTypePhotoLibrary,
UIImagePickerControllerSourceTypeCamera,
UIImagePickerControllerSourceTypeSavedPhotosAlbum
使用UIImagePickerController,请参阅Apple文档

选择源类型:

@property (nonatomic) UIImagePickerControllerSourceType sourceType
从那时起:

UIImagePickerControllerSourceTypePhotoLibrary,
UIImagePickerControllerSourceTypeCamera,
UIImagePickerControllerSourceTypeSavedPhotosAlbum
试试这个代码

它有助于您从cameraroll&photolibrary获取图像。使用UIImagePickerViewController

如果你拍照

从两个打开的摄像头,作为UINavigationcontroller。 从Galleryfor ipad作为UIpopovercontroller打开,从iphone作为nvigationcontroller打开。 第一组委托

从图库获取图像

这两个结果都是在委托方法中得到的

试试这个代码

它有助于您从cameraroll&photolibrary获取图像。使用UIImagePickerViewController

如果你拍照

从两个打开的摄像头,作为UINavigationcontroller。 从Galleryfor ipad作为UIpopovercontroller打开,从iphone作为nvigationcontroller打开。 第一组委托

从图库获取图像

这两个结果都是在委托方法中得到的

UIImagePickerViewController的类引用是您最好的朋友。UIImagePickerViewController的类引用是您最好的朋友。
 if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
    {
        UIImagePickerController *_picker=nil;
        if (popoverController) {
            [popoverController dismissPopoverAnimated:NO];

        }
        _picker = [[UIImagePickerController alloc] init];
        _picker.delegate = self;        
        _picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        _picker.wantsFullScreenLayout = YES;

        //[popoverController presentPopoverFromBarButtonItem:sender
                               //   permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {

           [self presentViewController:_picker animated:YES completion:nil];


        } else
        {
            popoverController = [[UIPopoverController alloc] initWithContentViewController:_picker];
            [popoverController setDelegate:self];
            [popoverController presentPopoverFromRect:btn.frame
                                               inView:self.view
                             permittedArrowDirections:UIPopoverArrowDirectionLeft
                                             animated:YES];
        }
    }
    else
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error access photo library"
                                                        message:@"your device non support photo library"
                                                       delegate:nil
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];
        [alert show];

    }
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
   // write your code here ........
 }