@@ -5,7 +5,6 @@ import com.guhungry.photomanipulator.factory.AndroidFactory
5
5
import com.guhungry.photomanipulator.factory.AndroidConcreteFactory
6
6
import java.io.IOException
7
7
import java.io.InputStream
8
- import kotlin.math.floor
9
8
10
9
object BitmapUtils {
11
10
@JvmStatic
@@ -75,7 +74,7 @@ object BitmapUtils {
75
74
// This uses scaling mode COVER
76
75
// Where would the crop rect end up within the scaled bitmap?
77
76
val crop = findCropPosition(cropSize, targetSize, outOptions.inSampleSize)
78
- val scaleMatrix = findCropScale(cropSize , targetSize, outOptions.inSampleSize )
77
+ val scaleMatrix = findCropScale(crop , targetSize)
79
78
80
79
return Bitmap .createBitmap(bitmap, crop.origin.x, crop.origin.y, crop.size.width, crop.size.height, scaleMatrix, true )
81
80
}
@@ -105,18 +104,17 @@ object BitmapUtils {
105
104
106
105
return CGRect (applyScale(newX, sampleSize), applyScale(newY, sampleSize), applyScale(newWidth, sampleSize), applyScale(newHeight, sampleSize))
107
106
}
108
- private fun applyScale (value : Float , sampleSize : Int ) = floor(value / sampleSize).toInt()
107
+ private fun applyScale (value : Float , sampleSize : Int ) = kotlin.math. floor(value / sampleSize).toInt()
109
108
110
- private fun findCropScale (rect : CGRect , targetSize : CGSize , sampleSize : Int ): Matrix {
109
+ private fun findCropScale (rect : CGRect , targetSize : CGSize ): Matrix {
111
110
val cropRectRatio = rect.size.ratio()
112
111
val targetRatio = targetSize.ratio()
113
112
114
- val scale = if (cropRectRatio > targetRatio) { // e.g. source is landscape, target is portrait
113
+ val cropScale = if (cropRectRatio > targetRatio) { // e.g. source is landscape, target is portrait
115
114
targetSize.height / rect.size.height.toFloat()
116
115
} else { // e.g. source is landscape, target is portrait
117
116
targetSize.width / rect.size.width.toFloat()
118
117
}
119
- val cropScale = scale * sampleSize
120
118
return Matrix ().apply { setScale(cropScale, cropScale) }
121
119
}
122
120
0 commit comments