55namespace BootstrapBlazor . Server . Components . Samples ;
66
77/// <summary>
8- /// ImageCroppers
8+ /// ImageCropper 组件示例
99/// </summary>
1010public partial class ImageCroppers
1111{
12+ private ImageCropper _cropper = default ! ;
1213
13- [ NotNull ]
14- ImageCropper ? Cropper { get ; set ; }
14+ private ImageCropper _roundCropper = default ! ;
1515
16- private string [ ] images = [ "./images/picture.jpg" , "./images/ImageList2.jpeg" ] ;
16+ private readonly string [ ] images = [ "./images/picture.jpg" , "./images/ImageList2.jpeg" ] ;
1717
1818 private int index = 0 ;
1919
20- private string ? Base64 { get ; set ; }
20+ private string ? _base64String ;
21+
22+ private string ? _base64String2 ;
23+
24+ private ImageCropperOption _roundOptions = new ( ) { IsRound = true , Radius = "50%" } ;
2125
2226 private async Task OnClickReplace ( )
2327 {
2428 index = index == 0 ? 1 : 0 ;
25- await Cropper . Replace ( images [ index ] ) ;
29+ await _cropper . Replace ( images [ index ] ) ;
30+ }
31+
32+ private async Task Crop ( )
33+ {
34+ _base64String = await _cropper . Crop ( ) ;
2635 }
2736
37+ private async Task RoundCrop ( )
38+ {
39+ _base64String2 = await _roundCropper . Crop ( ) ;
40+ }
41+
42+ private Task Rotate ( ) => _cropper . Rotate ( 90 ) ;
43+
2844 /// <summary>
2945 /// GetAttributes
3046 /// </summary>
@@ -41,51 +57,35 @@ protected AttributeItem[] GetAttributes() =>
4157 } ,
4258 new ( )
4359 {
44- Name = "DefaultButton " ,
45- Description = Localizer [ "AttributesImageCropperDefaultButton " ] ,
60+ Name = "IsDisabled " ,
61+ Description = Localizer [ "AttributesImageCropperIsDisabled " ] ,
4662 Type = "bool" ,
47- ValueList = "- " ,
48- DefaultValue = "true "
63+ ValueList = "true|false " ,
64+ DefaultValue = "false "
4965 } ,
5066 new ( )
5167 {
52- Name = "Preview" ,
53- Description = Localizer [ "AttributesImageCropperPreview" ] ,
54- Type = "bool" ,
55- ValueList = "-" ,
56- DefaultValue = "true"
57- } ,
58- new ( )
59- {
60- Name = "OnResult()" ,
61- Description = Localizer [ "AttributesImageCropperOnResult" ] ,
62- Type = "Func" ,
63- ValueList = "-" ,
64- DefaultValue = "-"
65- } ,
66- new ( )
67- {
68- Name = "OnBase64Result()" ,
69- Description = Localizer [ "AttributesImageCropperOnBase64Result" ] ,
70- Type = "Func" ,
68+ Name = "OnCropAsync" ,
69+ Description = Localizer [ "AttributesImageCropperOnCropAsync" ] ,
70+ Type = "Func<ImageCropperResult, Task>" ,
7171 ValueList = "-" ,
7272 DefaultValue = "-"
7373 } ,
7474 new ( )
7575 {
76- Name = "Crop() " ,
77- Description = Localizer [ "AttributesImageCropperCrop " ] ,
78- Type = "Task " ,
76+ Name = "Options " ,
77+ Description = Localizer [ "AttributesImageCropperOptions " ] ,
78+ Type = "ImageCropperOption " ,
7979 ValueList = "-" ,
8080 DefaultValue = "-"
8181 } ,
8282 new ( )
8383 {
84- Name = "CropToStream() " ,
85- Description = Localizer [ "AttributesImageCropperCropToStream " ] ,
86- Type = "Task " ,
84+ Name = "CropperShape " ,
85+ Description = Localizer [ "AttributesImageCropperShape " ] ,
86+ Type = "ImageCropperShape " ,
8787 ValueList = "-" ,
8888 DefaultValue = "-"
89- } ,
89+ }
9090 ] ;
9191}
0 commit comments