I am trying to save BitmapImage on a file system using C # in UWP. The image is downloaded from Facebook using the api graphic and returned as BitmapImage. This part works and retrieves the image (as soon as I can save it, it is tested with photos that are simply deleted in the local folder). I am using the following code:
public static async Task<BitmapImage> GetProfilePicture(string userId){
BitmapImage profilePicture = new BitmapImage();
StorageFolder pictureFolder = await
ApplicationData.Current.LocalFolder.GetFolderAsync("ProfilePictures");
StorageFile pictureFile = await pictureFolder.GetFileAsync(userId + ".jpg");
IRandomAccessStream stream = await pictureFile.OpenAsync(FileAccessMode.Read);
profilePicture.SetSource(stream);
return profilePicture;
This also works, so I would just like to do the opposite. The preferred result would look like this:
public static async void SaveBitmapToFile(BitmapImage image, userId){
StorageFolder pictureFolder = await
ApplicationData.Current.LocalFolder.CreateFolderAsync(
"ProfilePictures",CreationCollisionOption.OpenIfExists);
}
I searched everywhere, trying to find a solution, but I can not find it for the UWP platform. How can I save a bitmap to a file? The extension should not be .jpg if it would be easier to use another extension.