gpt4 book ai didi

ios - 将 FBProfilePictureView 转为 UIImage

转载 作者:行者123 更新时间:2023-11-29 10:28:24 28 4
gpt4 key购买 nike

我有一个获取用户 profilePicture、lblUsername 和 lblEmail 的 Facebook 登录名。我知道 FBProfilePictureView 是一个包含 UIImageView 的 UIView。

那么,我要问的是如何将您从 Facebook 获得的 profilePicture 转换或“保存”为 UIImage?这是我的 LoginViewController.m。我已在 LoginViewController.h 文件中正确导入 Facebook SDK。

#import "LoginViewController.h"
#import <QuartzCore/QuartzCore.h>

@interface LoginViewController ()

- (void)toggleHiddenState:(BOOL)shouldHide;

@end

@implementation LoginViewController

- (void)viewDidLoad {
[super viewDidLoad];

[self toggleHiddenState:YES];
self.lblLoginStatus.text = @"";

self.loginButton.readPermissions = @[@"public_profile", @"email"];
self.loginButton.layer.cornerRadius = 0;
[self.loginButton.layer setBorderWidth:0.0f];

self.loginButton.delegate = self;


// UIImageView *image = nil;
//
// for (NSObject *pic in [self.profilePicture subviews]) {
// if ([pic isMemberOfClass:[UIImageView class]]) {
// UIImageView *objImg = (UIImageView *)pic;
// image = objImg.image;
// break;
// }
// }
//
// self.view.backgroundColor = [UIColor colorWithPatternImage:image];
//
// Do any additional setup after loading the view.
}

-(void)toggleHiddenState:(BOOL)shouldHide{
self.lblUsername.hidden = shouldHide;
self.lblEmail.hidden = shouldHide;
self.profilePicture.hidden = shouldHide;
self.loggedinwallpaper.hidden = shouldHide;
self.FBlogout.hidden = shouldHide;
}

-(void)toggleUnhiddenState:(BOOL)shouldShow{
self.loggedinwallpaper.hidden = NO;
}

-(void)loginViewShowingLoggedInUser:(FBLoginView *)loginView{
self.lblLoginStatus.text = @"";

[self toggleHiddenState:NO];
[self toggleUnhiddenState:YES];
}

-(void)loginViewShowingLoggedOutUser:(FBLoginView *)loginView{
self.lblLoginStatus.text = @"";

[self toggleHiddenState:YES];
}

-(void)loginViewFetchedUserInfo:(FBLoginView *)loginView user:(id<FBGraphUser>)user{
NSLog(@"%@", user);
self.profilePicture.profileID = user.objectID;
self.lblUsername.text = user.name;
self.lblEmail.text = [user objectForKey:@"email"];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *homeViewController = (UIViewController *)[storyboard instantiateViewControllerWithIdentifier:@"HomeViewController"];
[self presentViewController:homeViewController animated:YES completion:nil];

//
// for (NSObject *obj in [self.profilePicture subviews]) {
// if ([obj isMemberOfClass:[UIImageView class]]) {
// UIImageView *objImg = (UIImageView *)obj;
// image = objImg.image;
// break;
// }
// }
}



-(void)loginView:(FBLoginView *)loginView handleError:(NSError *)error{
NSLog(@"%@", [error localizedDescription]);
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}


#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
//- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// UIImage *image = _profilePicture;
// HomeViewController *homeviewController = (HomeViewController *)segue.destinationViewController;
// homeviewController.homepic = image;
//

// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
//}


@end

最佳答案

我不会使用这样的图像,因为 facebook 会加载该图像的不同尺寸,而您不知道是否会得到低质量的版本。您不能自行下载所需大小的图片吗?

Facebook 使用这样的 url: http://graph.facebook.com/USER_ID/picture?width=WIDTH&height=HEIGHT

ofc 您需要将 USER_ID 换成用户的 facebook 用户 ID,将 WIDTHHEIGHT 换成您需要的值。

关于ios - 将 FBProfilePictureView 转为 UIImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30949089/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com