From ccd67e5d13f91b646801dd8c49df96c0057c19a5 Mon Sep 17 00:00:00 2001 From: Dhaval Patel Date: Fri, 17 Jul 2020 23:18:50 +0530 Subject: [PATCH] Get CompressFormat from extension Added method to get CompressFormat from extension --- .../dhaval2404/imagepicker/util/FileUtil.kt | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/imagepicker/src/main/kotlin/com/github/dhaval2404/imagepicker/util/FileUtil.kt b/imagepicker/src/main/kotlin/com/github/dhaval2404/imagepicker/util/FileUtil.kt index a2c88590..3b62a5f5 100644 --- a/imagepicker/src/main/kotlin/com/github/dhaval2404/imagepicker/util/FileUtil.kt +++ b/imagepicker/src/main/kotlin/com/github/dhaval2404/imagepicker/util/FileUtil.kt @@ -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 @@ -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 + } + } + } + }