I am having two buttons and an Image Control.
Now When I click 1st button I am trying to load an Image as shown below.
Dim openPicker As New FileOpenPicker
openPicker.ViewMode = PickerViewMode.Thumbnail
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary
openPicker.FileTypeFilter.Add(".jpg")
openPicker.FileTypeFilter.Add(".jpeg")
openPicker.FileTypeFilter.Add(".png")
Dim file As StorageFile = Await openPicker.PickSingleFileAsync
If Nothing IsNot file Then
Dim image As New BitmapImage()
Dim stream = Await file.OpenAsync(Windows.Storage.FileAccessMode.Read)
image.SetSource(stream)
Image1.Source = image
LayoutRoot.Visibility = Windows.UI.Xaml.Visibility.Collapsed
txtImgdisplay.Text = file.Path
Else
txtImgdisplay.Text = "Invalid File"
End If
Now when I Click 2nd button I need to save that Image after some modifications to the same image to pictures Library.
This is what I am trying to do and getting confused how to get the Image which is already loaded in the image control and save it.
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 Nothing IsNot saveFile Then
Dim image As New BitmapImage()
Dim stream = Await StorageFile.GetFileFromPathAsync(txtImgdisplay.Text)
LayoutRoot.Visibility = Windows.UI.Xaml.Visibility.Collapsed
txtImgdisplay.Text = saveFile.Path
Image1.Source = image
Dim copyFile As StorageFile = Await saveFile.CopyAsync(Windows.Storage.KnownFolders.PicturesLibrary, "sample - Copy.png")
Else
txtImgdisplay.Text = "Invalid File"
End If
I believe that all you need to do is call the Save method of the bitmap object.
image.Save(pathToPictureFolder & filename)
Try as follow. 1)store selected file(StorageFile)as member variable. 2)When Second Button is clicked.
FolderPicker saveFolder = new FolderPicker();
saveFolder.SuggestedStartLocation = PickerLocationId.Desktop;
saveFolder.FileTypeFilter.Add("*"); StorageFolder storagefolderSave = await saveFolder.PickSingleFolderAsync(); StorageFile storagefileSave = [selected storagefile as member variable] await storagefileSave.CopyAsync(storagefolderSave, storagefileSave.Name, NameCollisionOption.ReplaceExisting);