1

我有两个按钮和一个图像控件。

现在,当我单击第一个按钮时,我正在尝试加载图像,如下所示。

 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
4

2 回答 2

0

我相信您需要做的就是调用位图对象的 Save 方法。

image.Save(pathToPictureFolder & filename)
于 2012-04-06T12:27:00.300 回答
0

尝试如下。1)将选定的文件(StorageFile)存储为成员变量。2)当第二个按钮被点击时。

FolderPicker saveFolder = new FolderPicker();
saveFolder.SuggestedStartLocation = PickerLocationId.Desktop;
saveFolder.FileTypeFilter.Add("*"); StorageFolder storagefolderSave = 等待 saveFolder.PickSingleFolderAsync(); StorageFile storagefileSave = [选择的存储文件作为成员变量] await storagefileSave.CopyAsync(storagefolderSave, storagefileSave.Name, NameCollisionOption.ReplaceExisting);

于 2012-10-04T05:42:58.053 回答