Get and Set User Image in Windows Store App
Get and Set User Image in Windows Store App
Here is complete article >
GetAccountPicture and SetAccountPictureAsync methods are used to get and set the user's account picture.
The following code snippet gets the user's picture and displays in an Image control.
// Get account picture and display it in an Image control
StorageFile image = Windows.System.UserProfile.UserInformation.GetAccountPicture
(Windows.System.UserProfile.AccountPictureKind.SmallImage) as StorageFile;
if (image != null)
{
try
{
IRandomAccessStream imageStream = await image.OpenReadAsync();
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.SetSource(imageStream);
Image1.Source = bitmapImage;
Image1.Visibility = Visibility.Visible;
}
catch (Exception ex)
{
}
}
You need to make sure to import the following namespaces.
using Windows.Storage;
using Windows.Storage.Streams;
using Windows.UI.Xaml.Media.Imaging;