开发者

Uploading pictures to Facebook

I am writing an app that publishes pictures on Facebook using facebook-ios-sdk, but everytime I upload a picture, it's displayed with the wrong orientation on my album. Here's the code I am using, note that I account for the orientation on the second line:

   ALAssetRepresentation *rep = [currentAsset defaultRepresentation];

    UIImage *img = [UIImage imageWithCGImage:[rep fullResoluti开发者_如何转开发onImage] scale:[rep scale] orientation:[rep orientation]];        


    NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                    img, @"picture",
                                    [pictureCaptionTextView text], @"caption",
                                    nil];

    [facebook requestWithMethodName: @"photos.upload"
                           andParams: params
                       andHttpMethod: @"POST"
                         andDelegate: self];

    [img release];

Does anyone know what's going on? Should I pass the orientation when uploading it?


Have you tried using different photos, or are you testing on the same images each time? Sometimes an image will have EXIF data that will tell image programs to rotate it; it could be either that facebook is honoring EXIF data that your local app isn't and thus rotating or it could be that locally your program is displaying it rotated and facebook isn't.

Try viewing your photo in a few different browsers, and even better try downloading a photo from facebook and then re-uploading it =]


I finally figure this out thanks to this link.

The trick is that UIImageView automatically rotates the image correctly but the raw data is always on the default camera orientation (landscape, top to the right), so you need to adjust accordingly.

Bonus: this method resizes the image if you need to.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜