I have an image displayed in an Image Control and I need to save that Image using FileSavePicker
This is what I have done:
Dim fileSavePicker As New FileSavePicker()
fileSavePicker.FileTypeChoices.Add("PNG", New String() {".png"})
fileSavePicker.FileTypeChoices.Add("JPG", New String() {".jpg"})
fileSavePicker.FileTypeChoices.Add("BMP", New String() {".bmp"})
fileSavePicker.FileTypeChoices.Add("TIFF", New String() {".tiff"})
fileSavePicker.FileTypeChoices.Add("EXIF", New String() {".exif"})
fileSavePicker.FileTypeChoices.Add("ICO", New String() {".ico"})
Dim saveFile As StorageFile = Await fileSavePicker.PickSaveFileAsync()
If saveFile IsNot Nothing Then
//Here I need to save that Image
End If
It is saving the image but with “0 KB” and showing me the blank Image.
What should I be doing?
Edit:
This is the error I’m getting:
SaveToFile is not a memeber of Windows.UI.XAML.Media.Imaging.WriteableBitmap‘.
And similarly for ‘Load‘
Edit:
This is how I am trying to load image:
Private Async Sub Scenario1Button_Click(sender As Object, e As RoutedEventArgs) Handles Scenario1Button.Click
Image1.Visibility = Windows.UI.Xaml.Visibility.Visible
LayoutRoot.Visibility = Windows.UI.Xaml.Visibility.Collapsed
grdImages.Visibility = Windows.UI.Xaml.Visibility.Collapsed
Dim openPicker As New FileOpenPicker
openPicker.ViewMode = PickerViewMode.List
openPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary
openPicker.FileTypeFilter.Add("*")
Dim files As IReadOnlyList(Of StorageFile) = Await openPicker.PickMultipleFilesAsync
If files.Count > 0 Then
'Application now has read/write access to the picked file(s)
For Each file In files
Dim stream = Await file.OpenAsync(Windows.Storage.FileAccessMode.Read)
Dim image As New BitmapImage()
image.SetSource(stream)
Image1.Source = image
LayoutRoot.Visibility = Windows.UI.Xaml.Visibility.Collapsed
Next file
Else
End If
End Sub

According to the documentation:
So you get a storage file and you need to write to it.
Saving a BitmapImage is not possible, so you would need to start off by loading the image into a WriteableBitmap. If you are just copying the original file – you can just load it to a stream and save it back to the new storage file. If you want to go the WriteableBitmap route – here is a set of extension methods you could use to load/save the image if you used C#: