Skip to content

Commit 22d8f26

Browse files
committed
feat: 增加圆形头像示例
1 parent b262c4e commit 22d8f26

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

src/BootstrapBlazor.Server/Components/Samples/ImageCroppers.razor

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,16 @@
2626
</DemoBlock>
2727

2828
<DemoBlock Title="@Localizer["ImageCropperNormalText"]" Introduction="@Localizer["ImageCropperNormalIntro"]" Name="Normal">
29-
<ImageCropper Url="@images[0]" CropperShape="ImageCropperShape.Round" OnCropAsync="OnCropAsync" />
30-
@if (!string.IsNullOrEmpty(_base64String2))
31-
{
32-
<img src="@_base64String2" style="width: 240px;" />
33-
}
29+
<ImageCropper @ref="_roundCropper" Url="@images[0]" CropperShape="ImageCropperShape.Round" Options="_roundOptions" />
30+
<section ignore>
31+
<BootstrapInputGroup>
32+
<Button Text="OK" OnClick="RoundCrop" />
33+
</BootstrapInputGroup>
34+
@if (!string.IsNullOrEmpty(_base64String2))
35+
{
36+
<img src="@_base64String2" style="width: 240px;" />
37+
}
38+
</section>
3439
</DemoBlock>
3540

3641
<AttributeTable Items="@GetAttributes()" />

src/BootstrapBlazor.Server/Components/Samples/ImageCroppers.razor.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ public partial class ImageCroppers
1111
{
1212
private ImageCropper _cropper = default!;
1313

14+
private ImageCropper _roundCropper = default!;
15+
1416
private readonly string[] images = ["./images/picture.jpg", "./images/ImageList2.jpeg"];
1517

1618
private int index = 0;
@@ -19,6 +21,8 @@ public partial class ImageCroppers
1921

2022
private string? _base64String2;
2123

24+
private ImageCropperOption _roundOptions = new() { IsRound = true, Radius = "50%" };
25+
2226
private async Task OnClickReplace()
2327
{
2428
index = index == 0 ? 1 : 0;
@@ -30,11 +34,9 @@ private async Task Crop()
3034
_base64String = await _cropper.Crop();
3135
}
3236

33-
private Task OnCropAsync(ImageCropperResult result)
37+
private async Task RoundCrop()
3438
{
35-
_base64String2 = result.Data;
36-
StateHasChanged();
37-
return Task.CompletedTask;
39+
_base64String2 = await _roundCropper.Crop();
3840
}
3941

4042
private Task Rotate() => _cropper.Rotate(90);

0 commit comments

Comments
 (0)