Skip to content

Commit ba80310

Browse files
committed
Fixed initial overlay rect aspect ratio based on image
1 parent 2d31a94 commit ba80310

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

cropper/src/main/java/com/smarttoolfactory/cropper/state/CropStateImpl.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ abstract class CropState internal constructor(
7474
containerSize.width.toFloat(),
7575
containerSize.height.toFloat(),
7676
drawAreaSize.width.toFloat(),
77-
drawAreaSize.height.toFloat(),
7877
aspectRatio,
7978
overlayRatio
8079
),
@@ -158,7 +157,6 @@ abstract class CropState internal constructor(
158157
containerSize.width.toFloat(),
159158
containerSize.height.toFloat(),
160159
drawAreaSize.width.toFloat(),
161-
drawAreaSize.height.toFloat(),
162160
aspectRatio,
163161
overlayRatio
164162
)
@@ -398,16 +396,17 @@ abstract class CropState internal constructor(
398396
containerWidth: Float,
399397
containerHeight: Float,
400398
drawAreaWidth: Float,
401-
drawAreaHeight: Float,
402399
aspectRatio: AspectRatio,
403400
coefficient: Float
404401
): Rect {
405402

406403
if (aspectRatio == AspectRatio.Original) {
404+
val imageAspectRatio = imageSize.width.toFloat() / imageSize.height.toFloat()
407405

408406
// Maximum width and height overlay rectangle can be measured with
409407
val overlayWidthMax = drawAreaWidth.coerceAtMost(containerWidth * coefficient)
410-
val overlayHeightMax = drawAreaHeight.coerceAtMost(containerHeight * coefficient)
408+
val overlayHeightMax =
409+
(overlayWidthMax / imageAspectRatio).coerceAtMost(containerHeight * coefficient)
411410

412411
val offsetX = (containerWidth - overlayWidthMax) / 2f
413412
val offsetY = (containerHeight - overlayHeightMax) / 2f

cropper/src/main/java/com/smarttoolfactory/cropper/state/DynamicCropState.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,6 @@ class DynamicCropState internal constructor(
265265
containerSize.width.toFloat(),
266266
containerSize.height.toFloat(),
267267
drawAreaSize.width.toFloat(),
268-
drawAreaSize.height.toFloat(),
269268
aspectRatio,
270269
overlayRatio
271270
)

0 commit comments

Comments
 (0)