简体   繁体   English

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

[英]can't show picking image from photo library

Im using image picker for choose photos from photo library. 我正在使用图像选择器从照片库中选择照片。 When i click the button it displays photo library. 当我单击按钮时,它将显示照片库。 But when i click particular image it dismiss modalView and image won't load to view. 但是,当我单击特定图像时,它将关闭modalView,并且图像将不会加载以进行查看。

code: 码:

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


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

Declare this in .h 在.h中声明

UIImage *imgPicked; 

in ViewDidLoad ViewDidLoad

imgPicked = [[UIImage alloc]init];

Use this code: 使用此代码:

in .h file 在.h文件中

{
UIImageView *newImage;
    UIImagePickerController *imagePicker;
}

in .m file 在.m文件中

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

Best Way is Add Your Image to UIImageView , 最好的方法是将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];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM