//public async Task<BitmapImage> Base64ToImage(string base64String) //{ // // Convert base 64 string to byte[] // byte[] imageBytes = Convert.FromBase64String(base64String); // // Convert byte[] to Image // using (var ms = new MemoryStream(imageBytes, 0, imageBytes.Length)) // { // BitmapImage image = new BitmapImage(); // await image.SetSourceAsync(ms.AsRandomAccessStream()); // return image; // } //} private async Task LoadProfileImageAsync() { try { // Checkto see if we've previously saved it var imageFile = await ApplicationData.Current.LocalFolder.TryGetItemAsync("ProfilePicture.jpg"); if (imageFile == null) { // download the image var imageBytes = await mvpApiService.GetProfileImageAsync(); using (var ms = new MemoryStream(imageBytes, 0, imageBytes.Length)) { // Save the image imageFile = await ApplicationData.Current.LocalFolder.CreateFileAsync("ProfilePicture.jpg", CreationCollisionOption.ReplaceExisting); using (var fileStream = await((StorageFile)imageFile).OpenStreamForWriteAsync()) { ms.CopyTo(fileStream); } } } ProfileImageEllipse.Visibility = Visibility.Visible; ProfileImageBrush.ImageSource = new BitmapImage(new Uri("ms-appdata:///local/ProfilePicture.jpg")); } catch (Exception e) { Debug.WriteLine(e); } }
async Task RefreshProfileData() { if (Connectivity.NetworkAccess == NetworkAccess.Internet) { var profile = await _mvpApiService.GetProfileAsync().ConfigureAwait(false); var image = await _mvpApiService.GetProfileImageAsync().ConfigureAwait(false); Name = profile.FullName; ProfileImage = image; } }