Contact.GetPicture Method
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Gets a picture of the contact.
Assembly: Microsoft.Phone (in Microsoft.Phone.dll)
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(); } }