I am trying to resize an image on Saving;
I have the sfImagEditor defined in the view like this :
<ContentPage.Content x:DataType="local:CameraViewModel">
<imageEditor:SfImageEditor
x:Name="Editor"
ImageSaving="SfImageEditor_ImageSaving"
Source="{Binding Picture}" />
</ContentPage.Content>
in the code behind I have this :
private void SfImageEditor_ImageSaving(object sender, Syncfusion.SfImageEditor.XForms.ImageSavingEventArgs args)
{
var photo = ImageSource.FromStream(() => args.Stream);
string photoAsString = _photoService.ToBase64String(photo);
MessagingCenter.Send<CameraEditView, string>(this, "NewImage", photoAsString);
args.Cancel = true;
_navigationService.GoBackAsync();
}
I see that one can pass size parameters on the Save method :
How do I do this when the save method is called from the save button in the sfImage.Editor control
|
<imageeditor:SfImageEditor Source="{Binding Image}" x:Name="editor" ImageSaving="editor_ImageSaving" /> |
|
public partial class MainPage : ContentPage
{
bool isImageSaved;
public MainPage()
{
InitializeComponent();
editor.ToolbarSettings.ToolbarItemSelected += ToolbarSettings_ToolbarItemSelected;
}
private void ToolbarSettings_ToolbarItemSelected(object sender, Syncfusion.SfImageEditor.XForms.ToolbarItemSelectedEventArgs e)
{
if(e.ToolbarItem.Name=="Save")
{
/// When we set the isImageSaved to false, the added code in the image saving event will work.
isImageSaved = false;
}
}
private void editor_ImageSaving(object sender, Syncfusion.SfImageEditor.XForms.ImageSavingEventArgs args)
{
if(!isImageSaved)
{
//// Restrict the saving when you click the Save button
args.Cancel = true;
isImageSaved = true;
//// Image will save in mentioned size
editor.Save(".png", new Size(213, 764));
}
}
} |