File tree Expand file tree Collapse file tree 2 files changed +8
-3
lines changed Expand file tree Collapse file tree 2 files changed +8
-3
lines changed Original file line number Diff line number Diff line change
1
+ import 'dart:math' ;
2
+
1
3
import 'package:custom_image_crop/src/models/params_model.dart' ;
2
4
import 'package:custom_image_crop/src/widgets/custom_image_crop_widget.dart' ;
3
5
@@ -25,11 +27,11 @@ CropFitParams calculateCropFitParams({
25
27
if (screenWidth <= screenHeight * aspectRatio) {
26
28
cropSizeWidth = screenWidth * cropPercentage;
27
29
cropSizeHeight = cropSizeWidth / aspectRatio;
28
- defaultScale = cropSizeWidth / imageWidth;
30
+ defaultScale = cropSizeWidth * max (imageWidth / imageHeight, 1.0 ) / imageWidth;
29
31
} else {
30
32
cropSizeHeight = screenHeight * cropPercentage;
31
33
cropSizeWidth = cropSizeHeight * aspectRatio;
32
- defaultScale = cropSizeHeight / imageHeight;
34
+ defaultScale = cropSizeHeight * max (imageHeight / imageWidth, 1.0 ) / imageHeight;
33
35
}
34
36
break ;
35
37
Original file line number Diff line number Diff line change @@ -28,15 +28,18 @@ OnCropParams caclulateOnCropParams({
28
28
29
29
switch (imageFit) {
30
30
case CustomImageFit .fillCropSpace:
31
+ double cropScale;
31
32
if (screenWidth > screenHeight * aspectRatio) {
32
33
uiSize = screenHeight;
33
34
cropSizeMax = imageHeight.toDouble ();
35
+ cropScale = max (cropSizeMax / imageWidth, 1.0 );
34
36
} else {
35
37
uiSize = screenWidth;
36
38
cropSizeMax = imageWidth.toDouble ();
39
+ cropScale = max (cropSizeMax / imageHeight, 1.0 );
37
40
}
38
41
translateScale = cropSizeMax / (uiSize * cropPercentage);
39
- scale = dataScale;
42
+ scale = dataScale * cropScale ;
40
43
break ;
41
44
42
45
case CustomImageFit .fitCropSpace:
You can’t perform that action at this time.
0 commit comments