private async void bt_add_Click(object sender, RoutedEventArgs e) { //创建一个系统通信可以读写和其他程序制度的联系人存储 ContactStore conStore = await ContactStore.CreateOrOpenAsync(ContactStoreSystemAccessMode.ReadWrite, ContactStoreApplicationAccessMode.ReadOnly); //新增联系人 ContactInformation conInfo = new ContactInformation(); //获取ContacInformation类的属性map表 var properties = await conInfo.GetPropertiesAsync(); //添加电话属性 properties.Add(KnownContactProperties.FamilyName, "test"); properties.Add(KnownContactProperties.Telephone, "123456789"); //创建联系人对象 StoredContact storedContact = new StoredContact(conStore, conInfo); //获取安装包的一张图片文件用作联系人的头像 StorageFile imagefile = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync("Assets/1.jpeg"); ///设置头像,将图片数据转化成Stream对象,在转化成IInputStream对象。 //打开文件的可读数据流 Stream stream = await imagefile.OpenStreamForReadAsync(); //用Stream对象转化成为IIputStream对象 IInputStream inputStream = stream.AsInputStream(); //用IInputStream 对象设置为联系人头像 await storedContact.SetDisplayPictureAsync(inputStream); //保存联系人 await storedContact.SaveAsync(); ///获取头像,接收到的图片数据为IRandomAccessStream类型,如果要展示出来,需要创建一个BitmapImage对象, IRandomAccessStream raStream = await storedContact.GetDisplayPictureAsync(); BitmapImage bi = new BitmapImage(); bi.SetSource(raStream); image.Source = bi; }
private async void bt_add_Click(object sender, RoutedEventArgs e) { //创建一个系统通信可以读写和其他程序制度的联系人存储 ContactStore conStore = await ContactStore.CreateOrOpenAsync(ContactStoreSystemAccessMode.ReadWrite, ContactStoreApplicationAccessMode.ReadOnly); //新增联系人 ContactInformation conInfo = new ContactInformation(); //获取ContacInformation类的属性map表 var properties = await conInfo.GetPropertiesAsync(); //添加电话属性 properties.Add(KnownContactProperties.FamilyName, "test"); properties.Add(KnownContactProperties.Telephone, "123456789"); //创建联系人对象 StoredContact storedContact = new StoredContact(conStore, conInfo); //获取安装包的一张图片文件用作联系人的头像 StorageFile imagefile = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync("Assets/1.jpeg"); ///设置头像,将图片数据转化成Stream对象,在转化成IInputStream对象。 //打开文件的可读数据流 Stream stream = await imagefile.OpenStreamForReadAsync(); //用Stream对象转化成为IIputStream对象 IInputStream inputStream = stream.AsInputStream(); //用IInputStream 对象设置为联系人头像 await storedContact.SetDisplayPictureAsync(inputStream); //保存联系人 await storedContact.SaveAsync(); ///获取头像,接收到的图片数据为IRandomAccessStream类型,如果要展示出来,需要创建一个BitmapImage对象, IRandomAccessStream raStream = await storedContact.GetDisplayPictureAsync(); BitmapImage bi = new BitmapImage(); bi.SetSource(raStream); image.Source = bi; }