Forum Xamarin.iOS

getting an UIImage from ProfilePictureView Facebook iOS SDK

I'm trying to get the UIImage from ProfilePictureView given in facebook sdk. the code displays the picture when i extracted the UIImageView and added to the main view controller. but when I try to get the UIImage out from the UIImageView I instantiated, then it gives me the default profile picture of facebook. Please help!

`
public override void ViewDidLoad ()
{
base.ViewDidLoad ();

// txt_fname.Text = _user.First_Name;
// txt_lname.Text = _user.Last_Name;
UIImageView y = new UIImageView();
UIImage image = new UIImage ();
// btn_photo.SetBackgroundImage (fb_profile, UIControlState.Normal);

        foreach (var x in fb_profile.Subviews) {
            if (x is UIImageView) {
                y = (UIImageView)x;

                btn_photo.SetBackgroundImage (y.Image, UIControlState.Normal);

            }
        }

View.AddSubview (y);`

Posts

  • KarthikeyanVKarthikeyanV USMember ✭✭

    You need to set the UIImageView frame.
    if (x is UIImageView)
    {
    y = (UIImageView)x;
    y.Frame = CGRect(50,100,45,50); //Change frame depend on your requirement
    btn_photo.SetBackgroundImage (y.Image, UIControlState.Normal);
    }

  • KalithGayashanKalithGayashan USMember

    It changed the size and the position of the uiImageView. but i still get the default facebook( the picture you get when you don't have any profile picture) when i added to the button's background image.

  • KienNguyenKienNguyen VNMember
    edited June 2015

    Hello Kalith,
    I found the solution by this article (http://stackoverflow.com/questions/11889725/how-can-i-convert-fbprofilepictureview-to-an-uiimage).
    You should put a delay before populate the image to your button. I my case the code is:

    fb_profile = new ProfilePictureView (new CGRect (50, 0, 220, 220));
    PerformSelector (new ObjCRuntime.Selector ("UserImage"), null, 1);

    The function

    [Export ("UserImage")]
    private void getUserImageFromFBProfile () {
    UIImageView y = new UIImageView();
    foreach (var x in fb_profile.Subviews) {
    if (x is UIImageView) {
    y = (UIImageView)x;
    btn_photo.SetBackgroundImage (y.Image, UIControlState.Normal);
    }
    }
    }

Sign In or Register to comment.