Use . toDrawable extension function in ImageUtil

This commit is contained in:
AntsyLich
2026-06-13 23:42:34 +06:00
parent 6ae79d255d
commit a6f0cec083
@@ -18,6 +18,7 @@ import androidx.core.graphics.alpha
import androidx.core.graphics.applyCanvas import androidx.core.graphics.applyCanvas
import androidx.core.graphics.blue import androidx.core.graphics.blue
import androidx.core.graphics.createBitmap import androidx.core.graphics.createBitmap
import androidx.core.graphics.drawable.toDrawable
import androidx.core.graphics.get import androidx.core.graphics.get
import androidx.core.graphics.green import androidx.core.graphics.green
import androidx.core.graphics.red import androidx.core.graphics.red
@@ -338,9 +339,9 @@ object ImageUtil {
decoder?.recycle() decoder?.recycle()
val whiteColor = Color.WHITE val whiteColor = Color.WHITE
if (image == null) return ColorDrawable(whiteColor) if (image == null) return whiteColor.toDrawable()
if (image.width < 50 || image.height < 50) { if (image.width < 50 || image.height < 50) {
return ColorDrawable(whiteColor) return whiteColor.toDrawable()
} }
val top = 5 val top = 5
@@ -381,7 +382,7 @@ object ImageUtil {
!color.isWhite() && color.isCloseTo(other) !color.isWhite() && color.isCloseTo(other)
} }
if (isNotWhiteAndCloseTo.all { it }) { if (isNotWhiteAndCloseTo.all { it }) {
return ColorDrawable(topLeftPixel) return topLeftPixel.toDrawable()
} }
val cornerPixels = listOf(topLeftPixel, topRightPixel, botLeftPixel, botRightPixel) val cornerPixels = listOf(topLeftPixel, topRightPixel, botLeftPixel, botRightPixel)
@@ -496,8 +497,8 @@ object ImageUtil {
val isLandscape = context.resources.configuration?.orientation == Configuration.ORIENTATION_LANDSCAPE val isLandscape = context.resources.configuration?.orientation == Configuration.ORIENTATION_LANDSCAPE
if (isLandscape) { if (isLandscape) {
return when { return when {
darkBG -> ColorDrawable(blackColor) darkBG -> blackColor.toDrawable()
else -> ColorDrawable(whiteColor) else -> whiteColor.toDrawable()
} }
} }
@@ -518,7 +519,7 @@ object ImageUtil {
intArrayOf(whiteColor, whiteColor, blackColor, blackColor) intArrayOf(whiteColor, whiteColor, blackColor, blackColor)
} }
darkBG -> { darkBG -> {
return ColorDrawable(blackColor) return blackColor.toDrawable()
} }
topIsBlackStreak || topIsBlackStreak ||
( (
@@ -537,7 +538,7 @@ object ImageUtil {
intArrayOf(whiteColor, whiteColor, blackColor, blackColor) intArrayOf(whiteColor, whiteColor, blackColor, blackColor)
} }
else -> { else -> {
return ColorDrawable(whiteColor) return whiteColor.toDrawable()
} }
} }