Finding the dominant color of an image in an Android @drawable

后端 未结 8 853
情深已故
情深已故 2020-11-28 20:42

You can understand why I\'m trying to find the dominant color in an image if you use Windows 7. When your mouse over a program in the taskbar, the background of that partic

8条回答
  •  不知归路
    2020-11-28 21:18

    To find the Dominant / Vibrant / Muted color from an image, use Palette:

    import:

    implementation 'androidx.palette:palette:1.0.0'
    

    usage:

        val bitmap = BitmapFactory.decodeResource(resources, R.drawable.image)
    
        Palette.Builder(bitmap).generate { it?.let {  palette ->
            val dominantColor = palette.getDominantColor(ContextCompat.getColor(context!!, R.color.defaultColor))
    
            // TODO: use dominant color
    
        } }
    

提交回复
热议问题