2012-09-10 36 views
7

在我開發的應用程序中,我使用用戶從相冊中選擇的圖像。我需要將該照片的高分辨率版本上傳到我的服務器。UIImagePickerControllerOriginalImage vs原始資產數據

我使用imagePickerController和我確定我有UIImagePickerControllerOriginalImage

  • 得到原資產2個選項

    • 使用的UIImage使用UIImagePickerControllerReferenceURL和 ALAssetsLibrary assetForURL(我不喜歡這個,因爲它提示 用戶使用自己的當前位置,即我不需要)

    我的問題是... 如果我使用第一個選項與第二個選項相比,圖像的質量有任何不同嗎?

    -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{ 
    
        //option 1 
          UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"]; 
          NSData *imgData = UIImagePNGRepresentation(image); 
    
        // option 2 (will prompt user to allow use of current location) 
          NSURL *imgURL = [info objectForKey:@"UIImagePickerControllerReferenceURL"]; 
          __block NSData* imgData; 
    
          ALAssetsLibrary *assetLibrary=[[ALAssetsLibrary alloc] init]; 
    
          [assetLibrary assetForURL:img 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]; 
           imgData = [NSData dataWithBytesNoCopy:buffer length:buffered freeWhenDone:YES]; 
          } 
             failureBlock:^(NSError *err) { 
              NSLog(@"Error: %@",[err localizedDescription]); 
             }]; 
         } 
    
  • +0

    我使用的是沒有位置權限的選項2,它能夠獲取那一個圖像。 (我仍然無法使用ALAssetsLibrary來訪問整個庫)。這適用於iOS 5和iOS 6。 –

    回答

    13

    我跑了一個測試比較使用這兩個選項的圖像。使用選項1,圖像是兩倍大(4.22 MB比2.04 MB)。看看Photoshop中的照片,質量似乎沒有任何重大差異。在查看關卡時,選項1創建的關卡並不平滑(下圖)。當查看文件屬性時,選項1創建的文件缺少選項2創建的文件所具有的某些「原點」,「相機」和「高級照片」選項。我還沒有決定要使用哪種方式,但希望這些信息能夠幫助別人!

    levels in Photoshop