kami13sep / jabber-net

Automatically exported from code.google.com/p/jabber-net
Other
0 stars 0 forks source link

How can I get the Picture of one of my gmail contact. I wanted to display that information in my screen? #33

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
How can I get the Picture of one of my gmail contact. I wanted to display 
that information in my screen?

Original issue reported on code.google.com by premchan...@gmail.com on 31 Jul 2008 at 6:14

GoogleCodeExporter commented 8 years ago
Do the vCard request as usual:

     private void jabberClient1_OnAuthenticate(object sender)
        {
            VCardIQ iq = new VCardIQ(jabberClient1.Document);
            iq.To = "hildjj@gmail.com";
            iq.Type = IQType.get;
            jabberClient1.Tracker.BeginIQ(iq, GotVcard, null);
        }

if you're on HEAD of subversion, do:

        private void GotVcard(object sender, IQ iq, object state)
        {
            if ((iq == null) || (iq.Type != IQType.result))
                return;
            VCard card = iq.Query as VCard;
            if (card == null)
                return;

            VCard.VPhoto photo = card.Photo;
            pictureBox1.Image = photo.Image;
        }

Otherwise, if you're on the 2.1 release version or earlier, do something like 
this:

 private void GotVcard(object sender, IQ iq, object state)
        {
            if ((iq == null) || (iq.Type != IQType.result))
                return;
            VCard card = iq.Query as VCard;
            if (card == null)
                return;

            // TODO: null checks
            VCard.VPhoto photo = card.Photo;
            byte[] bin = Convert.FromBase64String(photo["BINVAL"].InnerText);
            System.IO.MemoryStream ms = new System.IO.MemoryStream(bin);
            pictureBox1.Image = System.Drawing.Image.FromStream(ms);
        }

Original comment by hil...@gmail.com on 5 Aug 2008 at 10:25

GoogleCodeExporter commented 8 years ago
Thanks you, it helps me ;)

Original comment by labecot....@gmail.com on 4 Nov 2009 at 1:03