Unable to use saved image because file is locked

Dear,

When an image that is being saved in the imageeditor, it has to be used in a following step. 

First I invoke the Save() function on the imageeditor:

imageeditor.Save(filePath: newfilename);

Then, the ImageSaved() event is triggered with the following code

        private void imageeditor_ImageSaved(object sender, ImageSavedEventArgs e)
        {
            var locationofeditedimage = e.Location;
            BitmapImage myBitmapImage = new BitmapImage();
            myBitmapImage.BeginInit();
            myBitmapImage.UriSource = new Uri(locationofeditedimage);
            myBitmapImage.CacheOption = BitmapCacheOption.OnLoad;
            myBitmapImage.DecodePixelWidth = 100;
            myBitmapImage.EndInit();
            ImageSource image = myBitmapImage;
        }

However, it is somehow locked by the proces, giving the error

"The process cannot access the file 'xxxx' because it is being used by another process."


Do I need to reset the editor, or dispose somehow, so the file is being released?

Best regards,


5 Replies

ET Eswaran Thirugnanasambandam Syncfusion Team January 27, 2022 01:48 PM UTC

Hi Koen Janssens, 
 
We have prepared a sample with the provided code snippet and checked the reported problem “Unable to use saved image because file is locked”. But we are unable to reproduce it from our side. Please find the tested sample from the below link. 
 
 
If you still face the problem, can you revert by modifying the sample based on your scenario, this will help us to provide you with a better solution at the earliest. 
 
Regards, 
Eswaran. 



KO Koen replied to Eswaran Thirugnanasambandam February 9, 2022 02:53 PM UTC

Dear,

I have checked your sample project and that does work indeed. However, in my specific case it is still not working. I have created a repo with a small sample:  KoenJanssensPD/SyncfusionImageEditorTest (github.com)

Could you please check?
Basically, when you select an image in the left list, you can make edits in the editor on the right. When hitting CTRL-S the edited file is being saved as [originalfilename]_edited.[originalextension] in the same folder. After saving, the thumbnail of the edited image should be shown next to the original file... However, now, when hitting CTRL-S, the file is saved but it fails to retrieve that image to generate the thumbnail for it...




ET Eswaran Thirugnanasambandam Syncfusion Team February 11, 2022 04:51 PM UTC

Hi Koen Janssens, 
  
We can reproduce the reported problem from our side. We have forwarded it to the development team and will update further details on February 14, 2022. 
 
Regards, 
Eswaran 



VR Vignesh Ramesh Syncfusion Team February 15, 2022 08:54 AM UTC

Sorry for the delay. Currently, our development team is trying to find a workaround solution to overcome this problem by creating the edited image thumbnail using the stream from the ImageSaving event when saving the image. We will let you know the further details on February 15, 2022.



VR Vignesh Ramesh Syncfusion Team February 15, 2022 01:51 PM UTC

Hi Koen Janssens, 

As mentioned in our previous update, we have overcome this problem by creating the edited image thumbnail using the stream from the ImageSaving event when saving the image. Please find the updated code from below 
 
In EditableImage.cs 
 
 
public BitmapImage EditedImage 
{ 
    get { return editedImage; } 
    set 
    { 
        editedImage = value; 
        OnPropertyChanged(); 
        OnPropertyChanged(nameof(BitmapImageEditedThumbnail)); 
    } 
} 
 
public BitmapImage BitmapImageEditedThumbnail => editedImage != null ? editedImage : !string.IsNullOrEmpty(editedFileLocation) ? GenerateBitmap(editedFileLocation, 100) : null; 
 
 
In EditableImagesView.xaml 
 
 
<editor:SfImageEditor x:Name="ImageEditor" 
                      Grid.Column="1" 
                      ImageSource="{Binding ImageForEditor}" 
                      ImageSaving="ImageEditor_ImageSaving" 
                      ImageSaved="ImageEditor_ImageSaved"> 
</editor:SfImageEditor> 
 
 
In EditableImagesView.xaml.cs 
 
 
private void ImageEditor_ImageSaved(object sender, Syncfusion.UI.Xaml.ImageEditor.ImageSavedEventArgs e) 
{ 
    //viewModel.SelectedImage.EditedFileLocation = e.Location; 
} 
 
private void ImageEditor_ImageSaving(object sender, ImageSavingEventArgs e) 
{ 
    e.Stream.Seek(0, 0); 
    BitmapImage bitmapImage = new BitmapImage(); 
    bitmapImage.BeginInit(); 
    bitmapImage.StreamSource = e.Stream; 
    bitmapImage.DecodePixelWidth = 100; 
    bitmapImage.EndInit(); 
    viewModel.SelectedImage.EditedImage = bitmapImage; 
} 
 
 
Also, please find the modified sample from the below link. 

Regards, 
Vignesh Ramesh.

Loader.
Up arrow icon