- Home
- Forum
- Xamarin.Forms
- SfImageEditor retains lock on edited image file
SfImageEditor retains lock on edited image file
After opening an image with SfImageEditor, a lock is placed on the image file until we close our app. Even if we close the editor, the lock is still there until the app is shut down. This is a big problem because we are trying to edit the image and save the changes over the existing file. Is there a way to remove the lock which the SfImageEditor places on the file? There is no Dispose(), but is there anything similar we could use to dispose of the editor so the lock is removed?
SIGN IN To post a reply.
5 Replies
1 reply marked as answer
SS
Sridevi Sivakumar
Syncfusion Team
March 11, 2021 09:58 AM UTC
Hi Jonathan Ruland,
Greetings from Syncfusion.
We have analyzed your query and we were unable to get exact problem from that. You have mentioned “lock is still there”, for this please share image or video reference to represent to your problem.
If possible, please update us sample based on your application along with replication procedure.
This will be helpful for us to provide you better solution at the earliest.
Regards,
Sridevi S.
Greetings from Syncfusion.
We have analyzed your query and we were unable to get exact problem from that. You have mentioned “lock is still there”, for this please share image or video reference to represent to your problem.
If possible, please update us sample based on your application along with replication procedure.
This will be helpful for us to provide you better solution at the earliest.
Regards,
Sridevi S.
JR
Jonathan Ruland
March 16, 2021 08:17 AM UTC
Attached is my test app. To reproduce, run the app and press the "Select and edit an image" button. You will use the picker to select an image (any image will do). SfImageEditor will appear with the selected image. Save the image. An "access denied" exception will be thrown in ImageEditor::Imageeditor_ImageSaving.
Attachment: ImageEditorTest_301cb39.zip
Attachment: ImageEditorTest_301cb39.zip
SS
Sridevi Sivakumar
Syncfusion Team
March 17, 2021 02:22 PM UTC
Hi Jonathan Ruland,
We have checked the reported problem with the shared sample and we can resolve this problem by selecting the save image location manually.
In the below code snippet, we have created an interface to pass the file name and edited stream to the UWP project.
[Interface]:
We have checked the reported problem with the shared sample and we can resolve this problem by selecting the save image location manually.
In the below code snippet, we have created an interface to pass the file name and edited stream to the UWP project.
[Interface]:
|
public interface IPicture
{
void SavePictureToDisk(string filename, byte[] imageData);
} |
In Picture_UWP class we have used a picker to select the folder manually from the local folders to save the image.
[ImageEditor.cs]
|
private void Imageeditor_ImageSaving(object sender, ImageSavingEventArgs args)
{
args.Cancel = true;
var byteArray = GetImageStreamAsBytes(args.Stream);
DependencyService.Get<IPicture>().SavePictureToDisk("EditorImage", byteArray);
} |
[Picture_UWP]:
|
[assembly: Xamarin.Forms.Dependency(typeof(ImageEditorTest.UWP.Picture_UWP))]
namespace ImageEditorTest.UWP
{
...
public class Picture_UWP : IPicture
{
public async void SavePictureToDisk(string fileName, byte[] bytes)
{
var stream = new Windows.Storage.Streams.InMemoryRandomAccessStream();
await stream.WriteAsync(bytes.AsBuffer());
stream.Seek(0);
var wb = new WriteableBitmap(1, 1);
wb.SetSource(stream);
await SaveImageInSystem.SaveToPngImage(wb, PickerLocationId.PicturesLibrary, "EditorImage");
}
}
public static class SaveImageInSystem
{
public static async Task<FileUpdateStatus> SaveToPngImage(this WriteableBitmap bitmap, PickerLocationId location, string fileName)
{
var savePicker = new FileSavePicker
{
SuggestedStartLocation = location
};
savePicker.FileTypeChoices.Add("Png Image", new[] { ".png" });
savePicker.SuggestedFileName = fileName;
StorageFile sFile = await savePicker.PickSaveFileAsync();
if (sFile != null)
{
CachedFileManager.DeferUpdates(sFile);
using (var fileStream = await sFile.OpenAsync(FileAccessMode.ReadWrite))
{
BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, fileStream);
Stream pixelStream = bitmap.PixelBuffer.AsStream();
byte[] pixels = new byte[pixelStream.Length];
await pixelStream.ReadAsync(pixels, 0, pixels.Length);
encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore,
(uint)bitmap.PixelWidth,
(uint)bitmap.PixelHeight,
96.0,
96.0,
pixels);
await encoder.FlushAsync();
}
FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(sFile);
return status;
}
return FileUpdateStatus.Failed;
}
}
} |
We have modified the shared sample manually, please have a sample from the below link
https://www.syncfusion.com/downloads/support/directtrac/163399/ze/ImageEditorTest1153594757
Please let us know if you need any further assistance.
Regards,
Sridevi S.
Please let us know if you need any further assistance.
Regards,
Sridevi S.
Marked as answer
JR
Jonathan Ruland
March 18, 2021 02:58 PM UTC
Thanks! I will try this out.
SS
Sridevi Sivakumar
Syncfusion Team
March 19, 2021 05:42 AM UTC
Hi Jonathan Ruland,
Thanks for your update.
We will wait until hear from you.
Regards,
Sridevi S.
Thanks for your update.
We will wait until hear from you.
Regards,
Sridevi S.
SIGN IN To post a reply.
- 5 Replies
- 2 Participants
- Marked answer
-
JR Jonathan Ruland
- Mar 10, 2021 08:34 PM UTC
- Mar 19, 2021 05:42 AM UTC