如何从图像中提取最突出的颜色?

How to extract the most prominent colour from an image?

我打算开发一个音乐播放器应用程序,我想 ui 使按钮根据正在查看的专辑的专辑封面中最突出的颜色改变颜色其他情况要么是预选颜色,要么是当前正在播放的歌曲专辑的突出颜色。

我想知道是否有人知道从图像中提取最突出颜色的方法。

有一个很好的 API 可以让你轻松地做到这一点,叫做调色板。它允许您从您提供的 Bitmap 中选择颜色,如下所示:

Palette palette = Palette.generate(myBitmap);
int vibrant = palette.getVibrantColor(0x000000);
int vibrantLight = palette.getLightVibrantColor(0x000000);
int vibrantDark = palette.getDarkVibrantColor(0x000000);
int muted = palette.getMutedColor(0x000000);
int mutedLight = palette.getLightMutedColor(0x000000);
int mutedDark = palette.getDarkMutedColor(0x000000);

依赖是'com.android.support:palette-v7:21.0.0'

我认为这将完全满足您的需求。单击 here 获取有关如何实施它的完整指南。

您可以使用 Google 调色板功能: http://developer.android.com/reference/android/support/v7/graphics/Palette.html