Windows Dev Center

Contact.GetPicture Method

Gets a picture of the contact.

Namespace:  Microsoft.Phone.UserData
Assembly:  Microsoft.Phone (in Microsoft.Phone.dll)

public Stream GetPicture()

Return Value

Type: System.IO.Stream
A stream that contains the data for the picture.

The following example assumes that you have a Windows Phone application that has a page with an image control named Picture. For the full example, including the XAML, see How to display the photo of a contact for Windows Phone 8.

void Contacts_SearchCompleted(object sender, ContactsSearchEventArgs e)
{
    try
    {
        //We are using only the first contact.
        Contact con = e.Results.First();

        BitmapImage img = new BitmapImage();
        img.SetSource(con.GetPicture());
        Picture.Source = img;
    }
    catch (Exception)
    {
        //We can't get a picture of the contact.
    }
}

The following example creates a data converter that you can use to data-bind contact photos directly to the UI. For the full example, including the XAML, see How to display the photo of a contact for Windows Phone 8.

public class ContactPictureConverter : System.Windows.Data.IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        Contact c = value as Contact;
        if (c == null) return null;

        System.IO.Stream imageStream = c.GetPicture();
        if (null != imageStream)
        {
            return Microsoft.Phone.PictureDecoder.DecodeJpeg(imageStream);
        }
        return null;
    }

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

Windows Phone OS

Supported in: 8.1, 8.0, 7.1

Windows Phone

Show:
© 2015 Microsoft