在Windows应用商店应用中保存图像

时间:2012-04-05 21:25:40

标签: .net vb.net image save windows-store-apps

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

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

 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

2 个答案:

答案 0 :(得分:0)

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

image.Save(pathToPictureFolder & filename)

答案 1 :(得分:0)

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

  

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