Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions compressor/src/main/java/id/zelory/compressor/Util.kt
Original file line number Diff line number Diff line change
@@ -38,10 +38,17 @@ fun decodeSampledBitmapFromFile(imageFile: File, reqWidth: Int, reqHeight: Int):
return BitmapFactory.Options().run {
inJustDecodeBounds = true
BitmapFactory.decodeFile(imageFile.absolutePath, this)

inSampleSize = calculateInSampleSize(this, reqWidth, reqHeight)

inJustDecodeBounds = false
val outRatio = outWidth.toFloat() / outHeight.toFloat()
val reqRatio = reqWidth.toFloat() / reqHeight.toFloat()
if (outRatio > reqRatio) {
inDensity = outHeight
inTargetDensity = reqHeight * inSampleSize
} else if (outRatio <= reqRatio) {
inDensity = outWidth
inTargetDensity = reqWidth * inSampleSize
}
BitmapFactory.decodeFile(imageFile.absolutePath, this)
}
}
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ class ResolutionConstraint(private val width: Int, private val height: Int) : Co
return BitmapFactory.Options().run {
inJustDecodeBounds = true
BitmapFactory.decodeFile(imageFile.absolutePath, this)
calculateInSampleSize(this, width, height) <= 1
outWidth - width <= 0 || outHeight - height <= 0
}
}