Palette的简单使用

Palette实际就是一个调色板,用来分析图片的颜色特征,如柔和的,鲜艳的,等等,可用来分析图片的色彩特征,这样可以用来保证应用颜色的统一。

  • 使用之前先要在gradle中进行配置
dependencies {
    ...
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile 'com.android.support:palette-v7:21.+'
    ...
}

Palette的基本使用如下:

BitmapDrawable drawable = (BitmapDrawable) iv.getDrawable();
        Bitmap bitmap = drawable.getBitmap();
        //得到bitmap里面的的一些色彩信息---通过Palette类分析出来的
//      Palette palette = Palette.generate(bitmap);
        //异步任务---可能分析的图片会比较大或者颜色分布比较复杂,会耗时比较久,防止卡死主线程。
        Palette.from(bitmap).generate(new PaletteAsyncListener() {

            @Override
            public void onGenerated(Palette palette) {
                //暗、柔和的颜色
                int darkMutedColor = palette.getDarkMutedColor(Color.BLUE);//如果分析不出来,则返回默认颜色
                //暗、柔和
                int lightMutedColor = palette.getLightMutedColor(Color.BLUE);
                //暗、鲜艳
                int darkVibrantColor = palette.getDarkVibrantColor(Color.BLUE);
                //亮、鲜艳
                int lightVibrantColor = palette.getLightVibrantColor(Color.BLUE);
                //柔和
                int mutedColor = palette.getMutedColor(Color.BLUE);
                //柔和
                int vibrantColor = palette.getVibrantColor(Color.BLUE);
                //获取某种特性颜色的样品
//              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();
                }

获取到对应的图片之后,使用Palette进行色彩分析,提取出不同的颜色,使用这些颜色对该界面的其他控件进行颜色的赋值,保证应用的主题统一。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值