Last active
November 8, 2022 19:55
-
-
Save ikhlaqmalik13/2e0b77d345504412c14cb5b8a6f8311b to your computer and use it in GitHub Desktop.
Palette usage to get the max colour from image and set it to GradientDrawable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
implementation 'androidx.palette:palette-ktx:1.0.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val bitmap: Bitmap = (imageView.drawable as BitmapDrawable).bitmap | |
Palette.from(bitmap).generate { palette -> | |
val swatch: Palette.Swatch? = palette?.darkMutedSwatch | |
swatch?.let { s -> | |
val mGradientMask = GradientDrawable( | |
GradientDrawable.Orientation.BOTTOM_TOP, | |
intArrayOf( | |
s.rgb, | |
s.rgb, | |
0x00000000 | |
) | |
) | |
binding.ivImageMask.background = mGradientMask | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment