亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

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 關注
  • 1692 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號