diff --git a/examples/Cropper.Blazor.MAUI.Net6/Cropper.Blazor.MAUI.Net6.csproj b/examples/Cropper.Blazor.MAUI.Net6/Cropper.Blazor.MAUI.Net6.csproj
index d394fa69..9ee658db 100644
--- a/examples/Cropper.Blazor.MAUI.Net6/Cropper.Blazor.MAUI.Net6.csproj
+++ b/examples/Cropper.Blazor.MAUI.Net6/Cropper.Blazor.MAUI.Net6.csproj
@@ -50,7 +50,7 @@
-
+
diff --git a/examples/Cropper.Blazor.MAUI.Net7/Cropper.Blazor.MAUI.Net7.csproj b/examples/Cropper.Blazor.MAUI.Net7/Cropper.Blazor.MAUI.Net7.csproj
index cfcbcb7a..a88302a5 100644
--- a/examples/Cropper.Blazor.MAUI.Net7/Cropper.Blazor.MAUI.Net7.csproj
+++ b/examples/Cropper.Blazor.MAUI.Net7/Cropper.Blazor.MAUI.Net7.csproj
@@ -51,7 +51,7 @@
-
+
diff --git a/examples/Cropper.Blazor.Server.Net6/Cropper.Blazor.Server.Net6.csproj b/examples/Cropper.Blazor.Server.Net6/Cropper.Blazor.Server.Net6.csproj
index 4566cee8..cc8a04b5 100644
--- a/examples/Cropper.Blazor.Server.Net6/Cropper.Blazor.Server.Net6.csproj
+++ b/examples/Cropper.Blazor.Server.Net6/Cropper.Blazor.Server.Net6.csproj
@@ -7,7 +7,7 @@
-
+
diff --git a/examples/Cropper.Blazor.Server.Net7/Cropper.Blazor.Server.Net7.csproj b/examples/Cropper.Blazor.Server.Net7/Cropper.Blazor.Server.Net7.csproj
index 3ea12789..1a2efe86 100644
--- a/examples/Cropper.Blazor.Server.Net7/Cropper.Blazor.Server.Net7.csproj
+++ b/examples/Cropper.Blazor.Server.Net7/Cropper.Blazor.Server.Net7.csproj
@@ -1,4 +1,4 @@
-
+
net7.0
@@ -7,7 +7,7 @@
-
+
diff --git a/examples/Cropper.MVC.With.Blazor.Server.Net7/Cropper.MVC.With.Blazor.Server.Net7.csproj b/examples/Cropper.MVC.With.Blazor.Server.Net7/Cropper.MVC.With.Blazor.Server.Net7.csproj
index 6b5a6dab..bf7f45f2 100644
--- a/examples/Cropper.MVC.With.Blazor.Server.Net7/Cropper.MVC.With.Blazor.Server.Net7.csproj
+++ b/examples/Cropper.MVC.With.Blazor.Server.Net7/Cropper.MVC.With.Blazor.Server.Net7.csproj
@@ -9,7 +9,7 @@
-
+
diff --git a/src/Cropper.Blazor/Client/Components/AspectRatioSettings.razor b/src/Cropper.Blazor/Client/Components/AspectRatioSettings.razor
new file mode 100644
index 00000000..6f039b66
--- /dev/null
+++ b/src/Cropper.Blazor/Client/Components/AspectRatioSettings.razor
@@ -0,0 +1,19 @@
+
+
+ Aspect Ratio Settings (only for FREE aspect ratio)
+
+
+
+
+
+ Current aspect ratio: @AspectRatio
+
+
+
diff --git a/src/Cropper.Blazor/Client/Components/AspectRatioSettings.razor.cs b/src/Cropper.Blazor/Client/Components/AspectRatioSettings.razor.cs
new file mode 100644
index 00000000..8d2535aa
--- /dev/null
+++ b/src/Cropper.Blazor/Client/Components/AspectRatioSettings.razor.cs
@@ -0,0 +1,89 @@
+using System.ComponentModel.DataAnnotations;
+using Cropper.Blazor.Client.Pages;
+using Cropper.Blazor.Models;
+using Microsoft.AspNetCore.Components;
+
+namespace Cropper.Blazor.Client.Components
+{
+ public partial class AspectRatioSettings
+ {
+ private decimal? maxAspectRatio;
+ private decimal? minAspectRatio;
+ private bool isEnableAspectRatioSettings;
+
+ public decimal? MaxAspectRatio
+ {
+ get => maxAspectRatio;
+ set
+ {
+ maxAspectRatio = value;
+ ApplyAspectRatioRulesForCropperAsync();
+ }
+ }
+
+ public decimal? MinAspectRatio
+ {
+ get => minAspectRatio;
+ set
+ {
+ minAspectRatio = value;
+ ApplyAspectRatioRulesForCropperAsync();
+ }
+ }
+
+ [CascadingParameter(Name = "AspectRatio"), Required]
+ private decimal? AspectRatio { get; set; }
+
+ [CascadingParameter(Name = "CropperDemo"), Required]
+ private CropperDemo CropperDemo { get; set; } = null!;
+
+ [CascadingParameter(Name = "IsEnableAspectRatioSettings"), Required]
+ private bool IsEnableAspectRatioSettings
+ {
+ get => isEnableAspectRatioSettings;
+ set
+ {
+ if (!value)
+ {
+ minAspectRatio = null;
+ maxAspectRatio = null;
+ }
+
+ isEnableAspectRatioSettings = value;
+ }
+ }
+
+ public async Task ApplyAspectRatioRulesForCropperAsync()
+ {
+ if (minAspectRatio is not null || maxAspectRatio is not null)
+ {
+ ContainerData containerData = await CropperDemo.CropperComponent!.GetContainerDataAsync();
+ CropBoxData cropBoxData = await CropperDemo.CropperComponent!.GetCropBoxDataAsync();
+
+ if (cropBoxData.Height != 0)
+ {
+ decimal aspectRatio = cropBoxData.Width / cropBoxData.Height;
+
+ if (aspectRatio < minAspectRatio || aspectRatio > maxAspectRatio)
+ {
+ decimal? newCropBoxWidth = cropBoxData.Height * ((minAspectRatio + maxAspectRatio) / 2);
+
+ CropperDemo.CropperComponent!.SetCropBoxData(new SetCropBoxDataOptions
+ {
+ Left = (containerData.Width - newCropBoxWidth) / 2,
+ Width = newCropBoxWidth,
+ });
+ }
+
+ SetUpAspectRatio(aspectRatio);
+ }
+ }
+ }
+
+ public void SetUpAspectRatio(decimal? aspectRatio)
+ {
+ AspectRatio = aspectRatio;
+ StateHasChanged();
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Cropper.Blazor/Client/Components/CroppedDimensionsSettings.razor b/src/Cropper.Blazor/Client/Components/CroppedDimensionsSettings.razor
new file mode 100644
index 00000000..cebea3b0
--- /dev/null
+++ b/src/Cropper.Blazor/Client/Components/CroppedDimensionsSettings.razor
@@ -0,0 +1,26 @@
+
+
+
+ Dimensions Settings
+ This option may not work with arbitrary 'Aspect Ratios' images, it is recommended to use a free Aspect Ratio for this option or calculate the allowed values yourself
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Cropper.Blazor/Client/Components/CroppedDimensionsSettings.razor.cs b/src/Cropper.Blazor/Client/Components/CroppedDimensionsSettings.razor.cs
new file mode 100644
index 00000000..d0673efa
--- /dev/null
+++ b/src/Cropper.Blazor/Client/Components/CroppedDimensionsSettings.razor.cs
@@ -0,0 +1,21 @@
+using System.ComponentModel.DataAnnotations;
+using Microsoft.AspNetCore.Components;
+
+namespace Cropper.Blazor.Client.Components
+{
+ public partial class CroppedDimensionsSettings
+ {
+ private decimal? minimumWidth = null;
+ private decimal? maximumWidth = null;
+ private decimal? minimumHeight = null;
+ private decimal? maximumHeight = null;
+
+ [CascadingParameter(Name = "ResetCropperAction"), Required]
+ public Action ResetCropperAction { get; set; } = null!;
+
+ public decimal? MinimumWidth { get => minimumWidth; set { minimumWidth = value; ResetCropperAction.Invoke(); } }
+ public decimal? MaximumWidth { get => maximumWidth; set { maximumWidth = value; ResetCropperAction.Invoke(); } }
+ public decimal? MinimumHeight { get => minimumHeight; set { minimumHeight = value; ResetCropperAction.Invoke(); } }
+ public decimal? MaximumHeight { get => maximumHeight; set { maximumHeight = value; ResetCropperAction.Invoke(); } }
+ }
+}
diff --git a/src/Cropper.Blazor/Client/Components/GetSetCropperData.razor b/src/Cropper.Blazor/Client/Components/GetSetCropperData.razor
index fc8583f6..e91f3b37 100644
--- a/src/Cropper.Blazor/Client/Components/GetSetCropperData.razor
+++ b/src/Cropper.Blazor/Client/Components/GetSetCropperData.razor
@@ -1,8 +1,10 @@
@using Cropper.Blazor.Models
-@*//---Cropper Data---//*@
-
+ @*//---Enable setup minimum and maximum cropped dimensions---//*@
+
+ @*//---Cropper Data---//*@
+
Cropper Data
@@ -70,8 +72,9 @@
@*//---Image Data---//*@
+
-
+
Image Data
@@ -95,7 +98,7 @@
@*//---Enable setup max/min zoom ratio---//*@
-
+
@*//---Canvas Data---//*@
diff --git a/src/Cropper.Blazor/Client/Components/GetSetCropperData.razor.cs b/src/Cropper.Blazor/Client/Components/GetSetCropperData.razor.cs
index 363fbc28..35c3868b 100644
--- a/src/Cropper.Blazor/Client/Components/GetSetCropperData.razor.cs
+++ b/src/Cropper.Blazor/Client/Components/GetSetCropperData.razor.cs
@@ -24,12 +24,15 @@ public partial class GetSetCropperData
[Parameter, Required]
public Func> GetCanvasData { get; set; } = null!;
+ public AspectRatioSettings AspectRatioSettings = null!;
+
private CropBoxData CropBoxData = null!;
private CropperData CropperData = null!;
private ContainerData ContainerData = null!;
private ImageData ImageData = null!;
private CanvasData CanvasData = null!;
- private ZoomRationSettings ZoomRationSettingszoomRationSettings = null!;
+ private ZoomRatioSettings ZoomRatioSettings = null!;
+ public CroppedDimensionsSettings CroppedDimensionsSettings = null!;
protected override void OnInitialized()
{
@@ -42,7 +45,7 @@ protected override void OnInitialized()
public void OnZoomEvent(ZoomEvent? zoomEvent)
{
- ZoomRationSettingszoomRationSettings!.OnZoomEvent(zoomEvent);
+ ZoomRatioSettings!.OnZoomEvent(zoomEvent);
}
public void SetCropBoxData(SetCropBoxDataOptions cropBoxDataOptions)
diff --git a/src/Cropper.Blazor/Client/Components/ZoomRationSettings.razor b/src/Cropper.Blazor/Client/Components/ZoomRatioSettings.razor
similarity index 63%
rename from src/Cropper.Blazor/Client/Components/ZoomRationSettings.razor
rename to src/Cropper.Blazor/Client/Components/ZoomRatioSettings.razor
index d56743e2..cedda9e3 100644
--- a/src/Cropper.Blazor/Client/Components/ZoomRationSettings.razor
+++ b/src/Cropper.Blazor/Client/Components/ZoomRatioSettings.razor
@@ -1,5 +1,6 @@
-
+
+ Zoom Ratio Settings
-
-
- Apply zoom rules for Cropper
-
-
diff --git a/src/Cropper.Blazor/Client/Components/ZoomRatioSettings.razor.cs b/src/Cropper.Blazor/Client/Components/ZoomRatioSettings.razor.cs
new file mode 100644
index 00000000..120ad49d
--- /dev/null
+++ b/src/Cropper.Blazor/Client/Components/ZoomRatioSettings.razor.cs
@@ -0,0 +1,49 @@
+using Cropper.Blazor.Events.ZoomEvent;
+using Microsoft.AspNetCore.Components;
+using Microsoft.JSInterop;
+
+namespace Cropper.Blazor.Client.Components
+{
+ public partial class ZoomRatioSettings
+ {
+ private decimal? minZoomRatio = null;
+ private decimal? maxZoomRatio = null;
+
+ private decimal? MinZoomRatio
+ {
+ get => minZoomRatio;
+ set
+ {
+ minZoomRatio = value;
+ ApplyZoomRulesForCropperAsync();
+ }
+ }
+ private decimal? MaxZoomRatio
+ {
+ get => maxZoomRatio;
+ set
+ {
+ maxZoomRatio = value;
+ ApplyZoomRulesForCropperAsync();
+ }
+ }
+ [Inject] private IJSRuntime? JSRuntime { get; set; }
+
+ private decimal? OldRatio { get; set; } = null;
+
+ private decimal? Ratio { get; set; } = null;
+
+ public void OnZoomEvent(ZoomEvent? zoomEvent)
+ {
+ OldRatio = zoomEvent?.OldRatio;
+ Ratio = zoomEvent?.Ratio;
+
+ StateHasChanged();
+ }
+
+ public async Task ApplyZoomRulesForCropperAsync()
+ {
+ await JSRuntime!.InvokeVoidAsync("window.overrideOnZoomCropperEvent", MinZoomRatio, MaxZoomRatio);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Cropper.Blazor/Client/Components/ZoomRationSettings.razor.cs b/src/Cropper.Blazor/Client/Components/ZoomRationSettings.razor.cs
deleted file mode 100644
index 318238dd..00000000
--- a/src/Cropper.Blazor/Client/Components/ZoomRationSettings.razor.cs
+++ /dev/null
@@ -1,31 +0,0 @@
-using Cropper.Blazor.Events.ZoomEvent;
-using Microsoft.AspNetCore.Components;
-using Microsoft.JSInterop;
-
-namespace Cropper.Blazor.Client.Components
-{
- public partial class ZoomRationSettings
- {
- private decimal? MinZoomRatio = null;
- private decimal? MaxZoomRatio = null;
-
- [Inject] private IJSRuntime? JSRuntime { get; set; }
-
- private decimal? OldRatio { get; set; } = null;
-
- private decimal? Ratio { get; set; } = null;
-
- public void OnZoomEvent(ZoomEvent? zoomEvent)
- {
- OldRatio = zoomEvent?.OldRatio;
- Ratio = zoomEvent?.Ratio;
-
- StateHasChanged();
- }
-
- public async Task ApplyZoomRulesForCropperAsync()
- {
- await JSRuntime!.InvokeVoidAsync("window.overrideCropperJsInteropModule", MinZoomRatio, MaxZoomRatio);
- }
- }
-}
diff --git a/src/Cropper.Blazor/Client/Cropper.Blazor.Client.csproj b/src/Cropper.Blazor/Client/Cropper.Blazor.Client.csproj
index dd59915f..0ebddae2 100644
--- a/src/Cropper.Blazor/Client/Cropper.Blazor.Client.csproj
+++ b/src/Cropper.Blazor/Client/Cropper.Blazor.Client.csproj
@@ -1,159 +1,163 @@
-
-
- IncludeGeneratedStaticFiles;
- $(ResolveStaticWebAssetsInputsDependsOn)
-
-
-
-
- false
-
-
-
- net7.0
- enable
- enable
- service-worker-assets.js
-
-
-
- false
- false
-
-
-
-
-
+
+
+ IncludeGeneratedStaticFiles;
+ $(ResolveStaticWebAssetsInputsDependsOn)
+
+
+
+
+ false
+
+
+
+ net7.0
+ enable
+ enable
+ service-worker-assets.js
+
+
+
+ false
+ false
+
+
+
+
+
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
- <_ContentIncludedByDefault Remove="Pages\CroppedCanvasDialog.razor" />
-
-
-
-
- $(MSBuildThisFileDirectory)../
-
-
-
-
-
-
- $(SolutionDir)Cropper.Blazor.Client.Compiler/bin/Debug/netcoreapp3.1/Cropper.Blazor.Client.Compiler.dll
-
-
-
-
- $(SolutionDir)Cropper.Blazor.Client.Compiler/bin/Debug/net7.0/Cropper.Blazor.Client.Compiler.dll
-
-
-
-
-
-
- dotnet run --configuration release --project "$(SolutionDir)Cropper.Blazor.Client.Compiler/Cropper.Blazor.Client.Compiler.csproj"
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- false
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+ <_ContentIncludedByDefault Remove="Pages\CroppedCanvasDialog.razor" />
+
+
+
+
+ $(MSBuildThisFileDirectory)../
+
+
+
+
+
+
+ $(SolutionDir)Cropper.Blazor.Client.Compiler/bin/Debug/netcoreapp3.1/Cropper.Blazor.Client.Compiler.dll
+
+
+
+
+ $(SolutionDir)Cropper.Blazor.Client.Compiler/bin/Debug/net7.0/Cropper.Blazor.Client.Compiler.dll
+
+
+
+
+
+
+ dotnet run --configuration release --project "$(SolutionDir)Cropper.Blazor.Client.Compiler/Cropper.Blazor.Client.Compiler.csproj"
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ false
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Cropper.Blazor/Client/Pages/CropperDemo.razor b/src/Cropper.Blazor/Client/Pages/CropperDemo.razor
index 968f4f67..2f3bd147 100644
--- a/src/Cropper.Blazor/Client/Pages/CropperDemo.razor
+++ b/src/Cropper.Blazor/Client/Pages/CropperDemo.razor
@@ -183,31 +183,31 @@
+ Style="@(AspectRatio == 1.7777777777777777m && !IsEnableAspectRatioSettings ? "background-color: var(--mud-palette-success-darken)" : "")" FullWidth="true">
16:9
+ Style="@(AspectRatio == 1.3333333333333333m && !IsEnableAspectRatioSettings ? "background-color: var(--mud-palette-success-darken)" : "")" FullWidth="true">
4:3
+ Style="@(AspectRatio == 1m && !IsEnableAspectRatioSettings ? "background-color: var(--mud-palette-success-darken)" : "")" FullWidth="true">
1:1
+ Style="@(AspectRatio == 0.6666666666666666m && !IsEnableAspectRatioSettings ? "background-color: var(--mud-palette-success-darken)" : "")" FullWidth="true">
2:3
-
+
Free
@@ -243,31 +243,31 @@
+ Style="@(AspectRatio == 1.7777777777777777m && !IsEnableAspectRatioSettings ? "background-color: var(--mud-palette-success-darken)" : "")" FullWidth="true">
16:9
+ Style="@(AspectRatio == 1.3333333333333333m && !IsEnableAspectRatioSettings ? "background-color: var(--mud-palette-success-darken)" : "")" FullWidth="true">
4:3
+ Style="@(AspectRatio == 1m && !IsEnableAspectRatioSettings ? "background-color: var(--mud-palette-success-darken)" : "")" FullWidth="true">
1:1
+ Style="@(AspectRatio == 0.6666666666666666m && !IsEnableAspectRatioSettings ? "background-color: var(--mud-palette-success-darken)" : "")" FullWidth="true">
2:3
-
+
Free
@@ -321,14 +321,22 @@
@*//+---// Get/Set all cropper data //---+//*@
-
+
+
+
+
+
+
+
+
+
diff --git a/src/Cropper.Blazor/Client/Pages/CropperDemo.razor.cs b/src/Cropper.Blazor/Client/Pages/CropperDemo.razor.cs
index b1a0791a..5cd905e8 100644
--- a/src/Cropper.Blazor/Client/Pages/CropperDemo.razor.cs
+++ b/src/Cropper.Blazor/Client/Pages/CropperDemo.razor.cs
@@ -25,13 +25,14 @@ public partial class CropperDemo : IDisposable
[Inject] private IJSRuntime? JSRuntime { get; set; }
- private CropperComponent? CropperComponent = null!;
+ public CropperComponent? CropperComponent = null!;
private CropperDataPreview? CropperDataPreview = null!;
private GetSetCropperData? GetSetCropperData = null!;
private Options Options = null!;
private decimal? ScaleXValue;
private decimal? ScaleYValue;
private decimal AspectRatio = 1.7777777777777777m;
+ private bool IsEnableAspectRatioSettings;
private string Src = "https://fengyuanchen.github.io/cropperjs/v2/picture.jpg";
private bool IsErrorLoadImage { get; set; } = false;
@@ -63,11 +64,34 @@ public async void OnCropEvent(JSEventData cropJSEvent)
ScaleXValue = cropJSEvent.Detail.ScaleX;
ScaleYValue = cropJSEvent.Detail.ScaleY;
- await InvokeAsync(() =>
+ decimal width = Math.Round(cropJSEvent.Detail.Width ?? 0);
+ decimal height = Math.Round(cropJSEvent.Detail.Height ?? 0);
+
+ if (width < GetSetCropperData!.CroppedDimensionsSettings.MinimumWidth
+ || height < GetSetCropperData!.CroppedDimensionsSettings.MinimumHeight
+ || width > GetSetCropperData!.CroppedDimensionsSettings.MaximumWidth
+ || height > GetSetCropperData!.CroppedDimensionsSettings.MaximumHeight
+ )
{
- //JSRuntime!.InvokeVoidAsync("console.log", $"CropJSEvent {JsonSerializer.Serialize(cropJSEvent)}");
- CropperDataPreview?.OnCropEvent(cropJSEvent.Detail);
- });
+ CropperComponent!.SetData(new SetDataOptions
+ {
+ Width = Math.Max(
+ GetSetCropperData!.CroppedDimensionsSettings.MinimumWidth ?? 0M,
+ Math.Min(GetSetCropperData!.CroppedDimensionsSettings.MaximumWidth ?? 0M, width)),
+ Height = Math.Max(
+ GetSetCropperData!.CroppedDimensionsSettings.MinimumHeight ?? 0M,
+ Math.Min(GetSetCropperData!.CroppedDimensionsSettings.MaximumHeight ?? 0M, height)),
+
+ });
+ }
+ else
+ {
+ await InvokeAsync(() =>
+ {
+ //JSRuntime!.InvokeVoidAsync("console.log", $"CropJSEvent {JsonSerializer.Serialize(cropJSEvent)}");
+ CropperDataPreview?.OnCropEvent(cropJSEvent.Detail);
+ });
+ }
}
}
@@ -132,6 +156,39 @@ public async void OnCropMoveEvent(JSEventData cropMoveJSEvent)
// await JSRuntime!.InvokeVoidAsync("console.log", $"CropMoveJSEvent OriginalEvent clientX: {clientX}");
//}
+ CropBoxData cropBoxData = await CropperComponent!.GetCropBoxDataAsync();
+
+ if (cropBoxData.Height != 0)
+ {
+ decimal aspectRatio = cropBoxData.Width / cropBoxData.Height;
+
+ AspectRatio = aspectRatio;
+ GetSetCropperData!.AspectRatioSettings.SetUpAspectRatio(aspectRatio);
+
+ if (GetSetCropperData?.AspectRatioSettings?.MinAspectRatio is not null
+ || GetSetCropperData?.AspectRatioSettings?.MaxAspectRatio is not null)
+ {
+ if (aspectRatio < GetSetCropperData!.AspectRatioSettings!.MinAspectRatio)
+ {
+ CropperComponent!.SetCropBoxData(new SetCropBoxDataOptions
+ {
+ Width = cropBoxData.Height * GetSetCropperData!.AspectRatioSettings.MinAspectRatio
+ });
+ }
+ else if (aspectRatio > GetSetCropperData!.AspectRatioSettings!.MaxAspectRatio)
+ {
+ CropperComponent!.SetCropBoxData(new SetCropBoxDataOptions
+ {
+ Width = cropBoxData.Height * GetSetCropperData!.AspectRatioSettings.MaxAspectRatio
+ });
+ }
+ }
+ }
+ else
+ {
+ AspectRatio = 0;
+ GetSetCropperData!.AspectRatioSettings.SetUpAspectRatio(0);
+ }
}
public async void OnCropReadyEvent(JSEventData jSEventData)
@@ -227,12 +284,20 @@ private void Destroy()
CropperComponent?.RevokeObjectUrlAsync(Src);
}
- public void SetAspectRatio(decimal aspectRatio)
+ public void SetAspectRatio(decimal aspectRatio, bool isEnableAspectRatioSettings = false)
{
- this.AspectRatio = aspectRatio;
+ IsEnableAspectRatioSettings = isEnableAspectRatioSettings;
+
+ if (aspectRatio != 0)
+ {
+ AspectRatio = aspectRatio;
+ }
+
CropperComponent?.SetAspectRatio(aspectRatio);
}
+ public void SetFreeAspectRatio() => SetAspectRatio(0, true);
+
public void SetViewMode(ViewMode viewMode)
{
Options.ViewMode = viewMode;
@@ -276,7 +341,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
- var subscriptionResult = await BreakpointListener.Subscribe((breakpoint) =>
+ var subscriptionResult = await BreakpointListener.SubscribeAsync((breakpoint) =>
{
InvokeAsync(StateHasChanged);
});
diff --git a/src/Cropper.Blazor/Client/Shared/CroppedCanvasDialog.razor b/src/Cropper.Blazor/Client/Shared/CroppedCanvasDialog.razor
index 8fd81c47..9759bb92 100644
--- a/src/Cropper.Blazor/Client/Shared/CroppedCanvasDialog.razor
+++ b/src/Cropper.Blazor/Client/Shared/CroppedCanvasDialog.razor
@@ -2,7 +2,9 @@
-
+
+
+
Cropped canvas data
@@ -12,13 +14,8 @@
-
+
+ Download image by link
+
-
-@code {
- [CascadingParameter] private MudDialogInstance MudDialog { get; set; } = null!;
-
- [Parameter]
- [System.ComponentModel.DataAnnotations.Required]
- public string Src { get; set; } = null!;
-}
\ No newline at end of file
+
\ No newline at end of file
diff --git a/src/Cropper.Blazor/Client/Shared/CroppedCanvasDialog.razor.cs b/src/Cropper.Blazor/Client/Shared/CroppedCanvasDialog.razor.cs
new file mode 100644
index 00000000..8fe26d08
--- /dev/null
+++ b/src/Cropper.Blazor/Client/Shared/CroppedCanvasDialog.razor.cs
@@ -0,0 +1,21 @@
+using Microsoft.AspNetCore.Components;
+using Microsoft.JSInterop;
+
+namespace Cropper.Blazor.Client.Shared
+{
+ public partial class CroppedCanvasDialog
+ {
+ [Parameter]
+ [System.ComponentModel.DataAnnotations.Required]
+ public string Src { get; set; } = null!;
+
+ [Inject] private IJSRuntime? JSRuntime { get; set; }
+
+ public async Task DownloadImageSrcAsync()
+ {
+ await JSRuntime!.InvokeVoidAsync(
+ "downloadFromUrl",
+ new { Url = Src, FileName = $"{Guid.NewGuid()}.png" });
+ }
+ }
+}
diff --git a/src/Cropper.Blazor/Client/Shared/MainLayout.razor.cs b/src/Cropper.Blazor/Client/Shared/MainLayout.razor.cs
index 2666d839..34fab34e 100644
--- a/src/Cropper.Blazor/Client/Shared/MainLayout.razor.cs
+++ b/src/Cropper.Blazor/Client/Shared/MainLayout.razor.cs
@@ -25,7 +25,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
- SubscriptionId = await ResizeService.Subscribe((size) =>
+ SubscriptionId = await ResizeService.SubscribeAsync((size) =>
{
if (size.Width > 960)
{
@@ -48,7 +48,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
await base.OnAfterRenderAsync(firstRender);
}
- public async ValueTask DisposeAsync() => await ResizeService.Unsubscribe(SubscriptionId);
+ public async ValueTask DisposeAsync() => await ResizeService.UnsubscribeAsync(SubscriptionId);
private async Task ApplyUserPreferences()
{
diff --git a/src/Cropper.Blazor/Client/wwwroot/helper.js b/src/Cropper.Blazor/Client/wwwroot/helper.js
new file mode 100644
index 00000000..b4af1b2a
--- /dev/null
+++ b/src/Cropper.Blazor/Client/wwwroot/helper.js
@@ -0,0 +1,7 @@
+window.downloadFromUrl = (options) => {
+ const anchorElement = document.createElement('a');
+ anchorElement.href = options.url;
+ anchorElement.download = options.fileName ?? '';
+ anchorElement.click();
+ anchorElement.remove();
+};
\ No newline at end of file
diff --git a/src/Cropper.Blazor/Client/wwwroot/index.html b/src/Cropper.Blazor/Client/wwwroot/index.html
index e8caaf14..ca7e8df9 100644
--- a/src/Cropper.Blazor/Client/wwwroot/index.html
+++ b/src/Cropper.Blazor/Client/wwwroot/index.html
@@ -130,6 +130,7 @@
+