无法显示从照片库中挑选图像

时间:2013-04-04 05:00:59

标签: iphone objective-c uiview uiimage uiimagepickercontroller

我使用图片选择器从照片库中选择照片。当我点击按钮时,它显示照片库。但是当我点击特定图像时,它会忽略modalView,并且图像将不会加载到视图中。

代码:

-(void)showcamera:(id)sender{

    UIImagePickerController *imagePickerController = [[UIImagePickerController alloc]init];
    imagePickerController = [[UIImagePickerController alloc] init];
    imagePickerController.delegate = self;
    imagePickerController.sourceType =  UIImagePickerControllerSourceTypePhotoLibrary;

    [self presentModalViewController:imagePickerController animated:YES];

}


- (void)imagePickerController:(UIImagePickerController *)picker
        didFinishPickingImage:(UIImage *)image
                  editingInfo:(NSDictionary *)editingInfo
{

    // Dismiss the image selection, hide the picker and

    //show the image view with the picked image

    [picker dismissModalViewControllerAnimated:YES];
    UIImage *newImage = image;


}

3 个答案:

答案 0 :(得分:1)

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    imgPicked = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
    {
        [imagePickerController dismissModalViewControllerAnimated:YES];
    }
}

在.h

中声明
UIImage *imgPicked; 
ViewDidLoad

中的

imgPicked = [[UIImage alloc]init];

答案 1 :(得分:1)

使用此代码:

<。>文件中的

{
UIImageView *newImage;
    UIImagePickerController *imagePicker;
}
<。>文件中的

- (void)imageTaped:(UITapGestureRecognizer *)tapGesture {
    imagePicker=[[UIImagePickerController alloc]init];

    imagePicker.delegate = self;

    imagePicker.allowsEditing =NO;

    imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

    [self presentModalViewController:imagePicker animated:YES];

}



-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
    //release picker
    [picker dismissModalViewControllerAnimated:YES];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    //set image


    newImage = [[UIImageView alloc] initWithImage:[info objectForKey:UIImagePickerControllerOriginalImage]];
    [self.view addSubview:mewImage];
    [picker dismissModalViewControllerAnimated:YES];
}

答案 2 :(得分:0)

最佳方式是将您的Image添加到UIImageView

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
     UIImageView *ImgView = [[UIImageView alloc] initWithFrame:CGRectMake(@"As U Want")];
     ImgView.image = image;
    [self.View addSubview: ImgView];


    [picker dismissModalViewControllerAnimated:YES];
}