Image saving in Windows Store App

Go To StackoverFlow.com

1

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
2012-04-05 21:25
by coder


0

I believe that all you need to do is call the Save method of the bitmap object.

image.Save(pathToPictureFolder & filename)
2012-04-06 12:27
by APrough
@Aprough-Thanks for your reply.But there is no Save Method for the Image - coder 2012-04-06 12:43
My apologies. I misread your code and thought it was a Bitmap, not a BitmapImage - APrough 2012-04-06 17:41
No problem.no need of apologies :) banging my head since today morning but couldn't figure it out - coder 2012-04-06 17:50


0

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);

2012-10-04 05:42
by Yu Li
Ads