Palette使用

2017-01-16  本文已影响0人  314a0097e21e

首先在gradle中增加依赖

dependencies { 
    ... 
    compile 'com.android.support:palette-v7:21.0.+' 
}

得到Palette对象

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的混合值---主色调
    int rgb = lightVibrantSwatch.getRgb();
    //谷歌推荐:图片中间的文字颜色
    int bodyTextColor = lightVibrantSwatch.getBodyTextColor();
    //谷歌推荐:作为标题的颜色(有一定的和图片的对比度的颜色值)
    int titleTextColor = lightVibrantSwatch.getTitleTextColor();
    //颜色向量
    float[] hsl = lightVibrantSwatch.getHsl();
    //分析该颜色在图片中所占的像素多少值
    int population = lightVibrantSwatch.getPopulation();

上一篇 下一篇

猜你喜欢

热点阅读