How can I convert FBProfilePictureView to an UIImage?

前端 未结 4 774
遥遥无期
遥遥无期 2020-12-03 05:18

Everything is working fine with FBProfilePictureView but I need to get that picture from FBProfilePictureView and turn it into an UIImage.

How should I do it?

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-03 06:05

    Above both mentioned solutions work fine to get UIImage object out from FBProfilePictureView. Only thing is, You need to put some delay before to get image from FBProfilePictureView. Like:

    [FBRequest requestForMe] startWithCompletionHandler:
         ^(FBRequestConnection *connection, NSDictionary *user, NSError *error) {
             if (!error) {
    
                 myNameLbl.text = user.name;
                 profileDP.profileID = user.id;
    
    //NOTE THIS LINE WHICH DOES THE MAGIC
    
    [self performSelector:@selector(getUserImageFromFBView) withObject:nil afterDelay:1.0];
    
    }];
    
    - (void)getUserImageFromFBView{
    
        UIImage *img = nil;
    
         //1 - Solution to get UIImage obj
    
         for (NSObject *obj in [profileDP subviews]) {
             if ([obj isMemberOfClass:[UIImageView class]]) {
                 UIImageView *objImg = (UIImageView *)obj;
                 img = objImg.image;
                 break;
             }
         }
    
        //2 - Solution to get UIImage obj
    
    //    UIGraphicsBeginImageContext(profileDP.frame.size);
    //    [profileDP.layer renderInContext:UIGraphicsGetCurrentContext()];
    //    img = UIGraphicsGetImageFromCurrentImageContext();
    //    UIGraphicsEndImageContext();
    
    //Here I'm setting image and it works 100% for me.
    
       testImgv.image = img;
    
    }
    

    Regards!

    Aamir Ali - iOS Apps Developer

    @Time Group (TGD)

提交回复
热议问题