iphone – didFinishPickingMediaWithInfo返回nil照片

我正在努力捕获在4.0使用返回的图像

- (void)imagePickerController:(UIImagePickerController *)picker 
    didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    [[picker parentViewController] dismissModalViewControllerAnimated:YES]; 

    // MediaType can be kUTTypeImage or kUTTypeMovie. If it's a movie then you
    // can get the URL to the actual file itself. This example only looks for images.
    //   
    NSString* mediaType = [info objectForKey:UIImagePickerControllerMediaType];
    // NSString* videoUrl = [info objectForKey:UIImagePickerControllerMediaURL];

    // Try getting the edited image first. If it doesn't exist then you get the
    // original image.
    //
    if (CFStringCompare((CFStringRef) mediaType,  kUTTypeImage, 0) == kCFCompareEqualTo) {               
        UIImage* picture = [info objectForKey:UIImagePickerControllerEditedImage];
        if (!picture)
            picture = [info objectForKey:UIImagePickerControllerOriginalImage];             

        // **picture is always nil
            // info dictionary count = 1


    }

}

发生的是信息字典总是返回一个条目:

{
UIImagePickerControllerMediaType =
“public.image”;

这是伟大的,但没有一个形象。

我使用了一个很好的例子从这个论坛做到这一点,我很确定电话是正确的,但从来没有一个图像。

提前致谢!

我知道这是很多个月后,但我努力了这个几个小时,在这个网站和iphonedevsdk.com发现了同样的问题,但从来没有一个工作的答案。

总而言之,如果图像是从相机胶卷/照片库中挑选,它工作正常,但如果图像是一个新的照片拍摄相机,它从来没有工作。嗯,这里是如何使它工作的两个:

你必须关闭并释放UIImagePickerController,然后再尝试对信息字典做任何事情。要超清楚:

这不工作:

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

          // No good with the edited image (if you allowed editing)
  myUIImageView.image = [info objectForKey:UIImagePickerControllerEditedImage];
          // AND no good with the original image
  myUIImageView.image = [info objectForKey:UIImagePickerControllerOriginalImage];
          // AND no doing some other kind of assignment
  UIImage *myImage = [info objectForKey:UIImagePickerControllerEditedImage];

  [picker dismissModalViewControllerAnimated:YES];
  [picker release];
}

在所有这些情况下,图像将为零。

但是,通过发布UIImagePickerController的魔法首先…

这个DOES工作:

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

疯狂简单,但这就是它的所有。

http://stackoverflow.com/questions/3088874/didfinishpickingmediawithinfo-return-nil-photo

本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:iphone – didFinishPickingMediaWithInfo返回nil照片