@@ -15,26 +15,40 @@ public enum BackgroundType
1515 Color ,
1616 StretchedImage
1717 }
18- // Отсутствует комментарий XML для открытого видимого типа или члена
18+
19+ /// <summary>
20+ /// Determines how the image is displayed.
21+ /// </summary>
22+ public enum BBAspect
23+ {
24+ AspectFit = 0 ,
25+ AspectFill = 1 ,
26+ Fill = 2 ,
27+ Auto = 3
28+ }
29+
30+
1931
2032 /// <summary>сonfigurator image editor</summary>
2133 public sealed class ImageEditorConfig : BaseNotifier
2234 {
23- private BackgroundType backgroundType = BackgroundType . Transparent ;
24- private Aspect aspect = Aspect . AspectFit ;
35+ private float ? сropAspectRatio ;
36+ public const int maxPixels = 3000 ;
37+
2538
2639 public const string _loadingText = "Wait" ;
2740 public const string _successSaveText = "Success" ;
2841 public const string _errorSaveText = "Error" ;
2942
43+
3044#pragma warning restore CS1591
3145
3246 /// <summary>constructor with default values</summary>
3347 public ImageEditorConfig ( ) { }
3448
3549 /// <summary></summary>
3650 public ImageEditorConfig ( bool canAddText = true , bool canFingerPaint = true , bool canTransformMainBitmap = true , float ? cropAspectRatio = null ,
37- List < SKBitmapImageSource > stickers = null , int ? outImageHeight = null , int ? outImageWidht = null , Aspect aspect = Aspect . AspectFit ,
51+ List < SKBitmapImageSource > stickers = null , int ? outImageHeight = null , int ? outImageWidht = null , BBAspect aspect = BBAspect . Auto ,
3852 BackgroundType backgroundType = BackgroundType . Transparent , SKColor backgroundColor = default ,
3953 bool canSaveImage = true , string loadingText = _loadingText , string successSaveText = _successSaveText , string errorSaveText = _errorSaveText )
4054 {
@@ -73,7 +87,11 @@ public ImageEditorConfig(bool canAddText = true, bool canFingerPaint = true, boo
7387 public string ErrorSaveText { get ; set ; } = _errorSaveText ;
7488
7589 /// <summary>sets and returns the aspect ratio for cropping the image </summary>
76- public float ? CropAspectRatio { get ; set ; } = null ;
90+ public float ? CropAspectRatio
91+ {
92+ get => сropAspectRatio ;
93+ set => сropAspectRatio = value <= 0 ? null : value ;
94+ }
7795
7896 /// <summary>sets a set of stickers.
7997 /// <para>do not use a large number of stickers this will lead to a large consumption of RAM</para>
@@ -91,18 +109,10 @@ public ImageEditorConfig(bool canAddText = true, bool canFingerPaint = true, boo
91109 public SKColor BackgroundColor { get ; set ; } = default ;
92110
93111 /// <summary>Defines the background type</summary>
94- public BackgroundType BackgroundType
95- {
96- get => IsOutImageAutoSize ? BackgroundType . Transparent : backgroundType ;
97- set => backgroundType = value ;
98- }
112+ public BackgroundType BackgroundType { get ; set ; } = BackgroundType . StretchedImage ;
99113
100114 /// <summary>Determines how the image is displayed</summary>
101- public Aspect Aspect
102- {
103- get => IsOutImageAutoSize ? Aspect . AspectFit : aspect ;
104- set => aspect = value ;
105- }
115+ public BBAspect Aspect { get ; set ; } = BBAspect . Auto ;
106116
107117 /// <summary>determines whether the user can change the aspect ratio when cropping an image </summary>
108118 public bool CanChangeCropAspectRatio => CropAspectRatio == null ;
@@ -121,10 +131,16 @@ public void SetOutImageSize(int? height = null, int? widht = null)
121131 OutImageHeight = null ;
122132 OutImageWidht = null ;
123133 }
134+ else if ( height > maxPixels || widht > maxPixels )
135+ {
136+ double outAspect = ( double ) widht / ( double ) height ;
137+ OutImageHeight = widht > height ? ( int ) ( maxPixels / outAspect ) : maxPixels ;
138+ OutImageWidht = widht > height ? maxPixels : ( int ) ( maxPixels * outAspect ) ;
139+ }
124140 else
125141 {
126- OutImageHeight = height < 3000 ? height : 3000 ;
127- OutImageWidht = widht < 3000 ? widht : 3000 ;
142+ OutImageHeight = height ;
143+ OutImageWidht = widht ;
128144 }
129145 }
130146
0 commit comments