我有两个按钮和一个图像控件。
现在,当我单击第一个按钮时,我正在尝试加载图像,如下所示。
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
现在,当我单击第二个按钮时,我需要在对同一图像进行一些修改后将该图像保存到图片库中。
这就是我正在尝试做的事情,并且对如何获取已经加载到图像控件中的图像并保存它感到困惑。
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