Skip to content

Commit

Permalink
Get CompressFormat from extension
Browse files Browse the repository at this point in the history
Added method to get CompressFormat from extension
  • Loading branch information
Dhaval2404 committed Jul 17, 2020
1 parent 1febc4c commit ccd67e5
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.dhaval2404.imagepicker.util

import android.graphics.Bitmap
import android.os.Environment
import android.os.StatFs
import java.io.File
Expand Down Expand Up @@ -83,4 +84,25 @@ object FileUtil {
val blockSize = stat.blockSizeLong
return availBlocks * blockSize
}

/**
* Get Bitmap Compress Format
*
* @param extension Image File Extension
* @return Bitmap CompressFormat
*/
fun getCompressFormat(extension: String): Bitmap.CompressFormat {
return when {
extension.contains("png", ignoreCase = true) -> {
Bitmap.CompressFormat.PNG
}
extension.contains("webp", ignoreCase = true) -> {
Bitmap.CompressFormat.WEBP
}
else -> {
Bitmap.CompressFormat.JPEG
}
}
}

}

0 comments on commit ccd67e5

Please sign in to comment.