首先在gradle中增加依賴
dependencies {?
??? ...?
??? compile 'com.android.support:palette-v7:21.0.+'?
}
得到Palette對(duì)象
Palette palette = Palette.from(bitmap).generate();
異步使用方式
Palette.from(bitmap).generate(new Palette.PaletteAsyncListener() {
@Override
public void onGenerated(Palette palette) {
//暗 柔和的顏色
int darkMutedColor = palette.getDarkMutedColor(Color.BLUE);
tx.setBackgroundColor(darkMutedColor);
}
});
一些API的使用
getDarkMutedColor?暗柔和??? getLightMutedColor亮柔和
getDarkVibrantColor 暗鮮艷 ?getLightVibrantColor亮鮮艷
getMutedColor?柔和????????????? getVibrantColor鮮艷
//??Swatch lightVibrantSwatch = palette.getLightVibrantSwatch();
????Swatch lightVibrantSwatch = palette.getVibrantSwatch();
????//谷歌推薦的:圖片的整體的顏色rgb的混合值---主色調(diào)
????int rgb = lightVibrantSwatch.getRgb();
????//谷歌推薦:圖片中間的文字顏色
????int bodyTextColor = lightVibrantSwatch.getBodyTextColor();
????//谷歌推薦:作為標(biāo)題的顏色(有一定的和圖片的對(duì)比度的顏色值)
????int titleTextColor = lightVibrantSwatch.getTitleTextColor();
????//顏色向量
????float[] hsl = lightVibrantSwatch.getHsl();
????//分析該顏色在圖片中所占的像素多少值
????int population = lightVibrantSwatch.getPopulation();