2012-06-20 113 views
0

我上傳照片到Facebook。 如果照片寬度>高,一切都OK。 但是,如果高度>寬度,facebook會調整照片,所以在Facebook帳戶照片中顯示寬度>高度,但(當然)方向錯誤。 我的代碼:上傳照片到facebook問題。錯誤的照片方向

- (void)postImageToFaceBook:(UIImage *)imgSource 
{ 
    [self login]; 

    currentAPICall = kAPIGraphUserPhotosPost; 

    NSString *strMessage = @"This is the photo caption"; 
    NSMutableDictionary* photosParams = [NSMutableDictionary dictionaryWithObjectsAndKeys: 
             imgSource,@"source", 
             strMessage,@"message", 
             nil]; 

    NSLog(@"Begin sending photo\n\n"); 
    [_facebook requestWithGraphPath:@"me/photos" 
          andParams:photosParams 
         andHttpMethod:@"POST" 
         andDelegate:self]; 
} 

- (void)login 
{ 
    if (![_facebook isSessionValid]) { 
     NSArray *permissions = [[NSArray alloc] initWithObjects: 
           @"user_photos", 
           nil]; 
     [_facebook authorize:permissions]; 
     [permissions release]; 
    } 
} 

- (void)logout 
{ 
    [_facebook logout]; 
} 


#pragma mark - FBRequestDelegate 

- (void)request:(FBRequest *)request didLoad:(id)result { 
    NSLog(@"Request load\n\n"); 
    [self hideHud]; 

    if ([result isKindOfClass:[NSArray class]] && ([result count] > 0)) { 
     result = [result objectAtIndex:0]; 
    } 

    switch (currentAPICall) { 
     case kAPIGraphPhotoData: // step 3 
     { 
      NSLog(@"sending to wall\n\n"); 
      // Facebook doesn't allow linking to images on fbcdn.net. So for now use default thumb stored on Picasa 

      NSString *thumbURL = kDefaultThumbURL; 
      NSString *imageLink = [NSString stringWithFormat:[result objectForKey:@"link"]];  

      currentAPICall = kDialogFeedUser; 


      NSMutableDictionary* dialogParams = [NSMutableDictionary dictionaryWithObjectsAndKeys: 
               kAppId, @"app_id", 
               imageLink, @"link", 
               thumbURL, @"picture", 
               @"Photo from my iPhone application", @"name", 
               @"The app", @"caption", 
               @"it is fun to use", @"description", 
               nil]; 

      [_facebook dialog:@"feed" 
        andParams:dialogParams 
        andDelegate:self]; 


      break; 
     } 
     case kAPIGraphUserPhotosPost: // step 2 
     { 
      NSLog(@"getting data\n\n"); 
      [self showHudWithMessage:@"Getting image data"]; 
      NSString *imageID = [NSString stringWithFormat:[result objectForKey:@"id"]];    
      NSLog(@"id of uploaded screen image %@",imageID); 

      currentAPICall = kAPIGraphPhotoData; 

      [_facebook requestWithGraphPath:imageID 
           andDelegate:self]; 

      break; 
     } 
     default: 
      break; 
    } 
} 


#pragma mark - FBDialogDelegate 

- (void)dialogDidComplete:(FBDialog *)dialog { 
    switch (currentAPICall) { 
     case kDialogFeedUser: 
     { 
      NSLog(@"Feed published successfully."); 
     } 
      break; 
     default: 
      break; 
    } 
} 

在postImageToFaceBook我檢查到的圖像尺寸是完全舒爾我的圖像寬度<高度。寬度約爲2200,高度爲3300,並且facebook相冊圖像顯示寬度>高度。

預先感謝您!

+0

您是否看到照片的Exif標籤是否造成這種情況? –

回答

0

我解決了這個問題。 這種行爲是當圖像的寬度大約爲2000像素,但如果寬度小於1000像素,則一切正常。

0

其實facebook在圖片上沒有做任何事情。 iPhone在縱向模式下顯示所有圖像時處於橫向模式。所以請檢查你的系統上的圖像。

謝謝

+0

不,在postImageToFaceBook我檢查圖像的大小,寬度約爲2200,高度爲3300,和facebook相冊圖像顯示寬度>高度。我更新了帖子 –

+0

你有沒有檢查你的系統中的圖像。 Bcoz幾天前我也面臨同樣的問題。並確保在fb上載它之前你沒有進行圖像大小調整。 –

+0

我檢查寬度後約爲2200,高度爲3300,我不調整圖像大小。你是什​​麼意思「你在系統中檢查過鏡像」。正如我之前所說,在發送之前我檢查了圖像大小。 –