We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

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

Platform: UWP |
Control: SfImageEditor |
Published Date: January 4, 2019 |
Last Revised Date: June 25, 2019

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.

2X faster development

The ultimate UWP UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon