Articles in this section
Category / Section

How to change the image saving location in the image editor control for UWP?

5 mins read

Description:

In image editor, by default, the image is saved into the Pictures directory. You change the default image saving location into your custom location.

 

Step 1: Create an image editor sample with all the necessary assemblies.

 

Refer to this getting started documentation to create a simple SfImageEditor sample and configure it.

 

Step 2: Select the desired folder using the PickSignleFolderAsync() framework method when saving the edited image in the image editor control.

 

Step 3: Get the path from the “Path” property after selected the desired folder. You can use this path to save the image to your custom location.

 

The following code sample demonstrates how to change the default image saving location into your custom location.

 

C#

 

public async void SelectDirectory(Stream stream)
{
    IRandomAccessStream randomAccessStream = stream.AsRandomAccessStream();
    var wbm = new WriteableBitmap(600, 800);
    await wbm.SetSourceAsync(randomAccessStream);
    string fileName = "image.jpg";
    var folderPicker = new Windows.Storage.Pickers.FolderPicker();
    folderPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.Desktop;
    folderPicker.FileTypeFilter.Add("*");
    Windows.Storage.StorageFolder folder = await folderPicker.PickSingleFolderAsync();
    string SelectedFolderPath = folder.Path;
    if (folder != null)
    {
        // Application now has read/write access to all contents in the picked folder
        // (including other sub-folder contents)
        Windows.Storage.AccessCache.StorageApplicationPermissions.
        FutureAccessList.AddOrReplace("PickedFolderToken", folder);
        StorageFile file = await folder.CreateFileAsync(fileName, CreationCollisionOption.GenerateUniqueName);
        using (var storageStream = await file.OpenAsync(FileAccessMode.ReadWrite))
        {
            var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, storageStream);
            var pixelStream = wbm.PixelBuffer.AsStream();
            var pixels = new byte[pixelStream.Length];
            await pixelStream.ReadAsync(pixels, 0, pixels.Length);
            encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore, (uint)wbm.PixelWidth, (uint)wbm.PixelHeight, 200, 200, pixels);
            await encoder.FlushAsync();
        }
    }
}

 

You can find the sample for changing the image saving location in this link: Sample.

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied