How to Maintain zoom state when performing crop, rotate, and transform actions in Blazor Image Editor?
Overview
The default functionality of the Syncfusion Blazor ImageEditor component is to reset the zoom factor when performing crop, rotate, and transform actions. This is done to display the entire image within the viewport for these actions. However, it is possible to preserve the zoom state after these actions by utilizing the ToolbarItemClicked event.
Maintaining zoom state
To maintain a consistent zoom factor after performing crop and transform actions, you can manage the ToolbarItemClicked event in a formal manner. This will ensure that the zoom state is preserved when either the Apply or Discard toolbar item is clicked.
Here is a code snippet that demonstrates how to implement this functionality:
<SfImageEditor @ref="ImageEditor" Height="500">
<ImageEditorEvents ToolbarItemClicked="ToolbarClicked"></ImageEditorEvents>
</SfImageEditor>
@code {
SfImageEditor ImageEditor;
private double ZoomFactor = 1;
private async void ToolbarClicked(Syncfusion.Blazor.Navigations.ClickEventArgs args)
{
if (args.Item.Id == "ok" || args.Item.Id == "cancel")
{
await ImageEditor.ZoomAsync(ZoomFactor);
}
else if (args.Item.Id == "zoomin" || args.Item.Id == "zoomout")
{
ZoomFactor = args.Item.Id == "zoomin" ? ZoomFactor + 1 : ZoomFactor - 1;
}
else if (args.Item.Id == "reset")
{
ZoomFactor = 1;
}
}
}
Example
To see this in action, you can refer to the following sample link: Syncfusion Blazor ImageEditor Sample
Additional References
Conclusion
We hope you enjoyed learning how to maintain zoom state when performing crop, rotate, and transform actions.
You can refer to our Blazor ImageEditor feature tour page to learn about its other groundbreaking features, documentation, and how to quickly get started with configuration specifications.
For current customers, our Blazor components are available on the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to evaluate our Blazor Image Editor and other Blazor components.
If you have any questions or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!