为了账号安全,请及时绑定邮箱和手机立即绑定

didFinishPickingMediaWithInfo返回无照片

didFinishPickingMediaWithInfo返回无照片

梵蒂冈之花 2019-11-30 14:00:47
我正在努力捕获使用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”;很棒,但是从来没有图像。我在这个论坛上使用了一个很好的例子来做到这一点,我很确定调用是正确的,但是从来没有图像。
查看完整描述

3 回答

?
慕的地10843

TA贡献1785条经验 获得超8个赞

尽管Matthew Frederick的回答最受欢迎,并且长期以来一直是适当的回应,从iOS 5.0(苹果可用)开始dismissViewControllerAnimated:completion:,以取代现已弃用的(从iOS 6.0开始)dismissViewControllerAnimated:。


希望在完成块中执行图像信息字典检索应该对所有人都有意义。


从上面举个例子,现在看起来像:


- (void)    imagePickerController:(UIImagePickerController *)picker 

    didFinishPickingMediaWithInfo:(NSDictionary *)info 

{

    [picker dismissViewControllerAnimated:YES completion:^{

          // 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];

    }];

}


查看完整回答
反对 回复 2019-11-30
?
慕标琳琳

TA贡献1830条经验 获得超9个赞

我已经尝试了所有上述操作,但是在iPad 6.0 / 6.1模拟器上却没有运气,但是我发现信息包含“ UIImagePickerControllerReferenceURL”键,这是我的代码:


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

  [picker dismissViewControllerAnimated:YES completion:NULL];


  UIImage* image = [info objectForKey:UIImagePickerControllerOriginalImage];

  if(NULL == image){

      [MyImageLoader loadImageFromAssertByUrl:[info objectForKey:@"UIImagePickerControllerReferenceURL"]

                                   completion:^(UIImage* img){

                                        //img not null here

                                   }];

  }else{

      //image not null here

  }

}

而loadImageFromAssertByUrl的代码是:


+(void) loadImageFromAssertByUrl:(NSURL *)url completion:(void (^)(UIImage*)) completion{

  ALAssetsLibrary *assetLibrary=[[ALAssetsLibrary alloc] init];

  [assetLibrary assetForURL:url resultBlock:^(ALAsset *asset) {

      ALAssetRepresentation *rep = [asset defaultRepresentation];

      Byte *buffer = (Byte*)malloc(rep.size);

      NSUInteger buffered = [rep getBytes:buffer fromOffset:0.0 length:rep.size error:nil];

      NSData *data = [NSData dataWithBytesNoCopy:buffer length:buffered freeWhenDone:YES];

      UIImage* img = [UIImage imageWithData:data];

      completion(img);

  } failureBlock:^(NSError *err) {

      NSLog(@"Error: %@",[err localizedDescription]);

  }];

}


查看完整回答
反对 回复 2019-11-30
  • 3 回答
  • 0 关注
  • 1605 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信