Skip to content

Instantly share code, notes, and snippets.

@ikhlaqmalik13
Last active November 8, 2022 19:55
Show Gist options
  • Save ikhlaqmalik13/2e0b77d345504412c14cb5b8a6f8311b to your computer and use it in GitHub Desktop.
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
implementation 'androidx.palette:palette-ktx:1.0.0'
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