private async Task CreateImages(WriteableBitmap image) { Log.Info("Creating tile images from user profile images"); var profileFileName = string.Format(Constants.ProfilePictureStorageFilePath, CurrentPlayer.Username); var normalFileName = string.Format(Constants.Tiles.UserProfileFileFormat, CurrentPlayer.Username); var wideFileName = string.Format(Constants.Tiles.UserProfileWideFileFormat, CurrentPlayer.Username); if (await _asyncStorageService.FileExistsAsync(normalFileName)) { await _asyncStorageService.DeleteFileAsync(normalFileName); } if (await _asyncStorageService.FileExistsAsync(wideFileName)) { await _asyncStorageService.DeleteFileAsync(wideFileName); } var normalTile = CreateProfileTileImages(image, 336, 336); var wideTile = CreateProfileTileImages(image, 336, 691); // Overwrite the profile image with the cropped version await Utils.SaveTile(normalTile, 336, 336, profileFileName); Messenger.Default.Send(new NotificationMessage(Constants.Messages.RefreshCurrentPlayerMsg)); await Utils.SaveTile(normalTile, 336, 336, normalFileName); await Utils.SaveTile(wideTile, 336, 691, wideFileName); Messenger.Default.Send(new NotificationMessage(Constants.Messages.UpdatePrimaryTileMsg)); }
private async Task SaveTheImage(WriteableBitmap bitmap) { if (await _storageService.FileExistsAsync(LockScreenFile)) { await _storageService.DeleteFileAsync(LockScreenFile); } using (var fileStream = await _storageService.CreateFileAsync(LockScreenFile)) { var encoder = new PngEncoder(); var image = bitmap.ToImage(); encoder.Encode(image, fileStream); } }