2012-06-20 117 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,我不调整图像大小。你是什​​么意思“你在系统中检查过镜像”。正如我之前所说,在发送之前我检查了图像大小。 –