美文网首页android
Android Palette

Android Palette

作者: 孤独的根号十二 | 来源:发表于2019-01-15 11:27 被阅读4次

作用:

Palette:可以在一张图片里面分析出一些色彩特性:主色调、鲜艳的颜色、柔和颜色等等

使用方法

1.引入v7里面的一个单独项目Palette,android.support.v7.graphics.Palette;
2.使用(分为同步和异步,建议使用异步)

//同步方式
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();

其他

得到沉浸透明的颜色:

    protected int getTranslucentColor(float percent, int rgb) {
        // 10101011110001111
        int blue = Color.blue(rgb);
        int green = Color.green(rgb);
        int red = Color.red(rgb);
        int alpha = Color.alpha(rgb);
//      int blue = rgb & 0xff;
//      int green = rgb>>8 & 0xff;
//      int red = rgb>>16 & 0xff;
//      int alpha = rgb>>>24;
        
        alpha = Math.round(alpha*percent);
        Toast.makeText(this, "alpha:"+alpha+",red:"+red+",green:"+green, 1).show();
        return Color.argb(alpha, red, green, blue);
    }

效果:

4p9648197AU422.gif

相关文章

  • Android Palette(调色板)的使用

    一、Palette的简单介绍 android-support-v7-palette 里面的Palette是Andr...

  • 主题颜色提取 ——— Palette

    Palette 调色板 Palette 是 Android L SDK 中的新特性。可以使用 Palette 从图...

  • android5.0新特性介绍

    1:Palette(需要添加依赖:compile 'com.android.support:palette-v7:...

  • Android Lollipop:使用Palette抽取图片主色

    使用Palette抽取Bitmap主色调 关于Palette 一些Support库随着Android Lollip...

  • Android 5.X 新特性详解

    本文是《Android群英传》的读书笔记 Material Design主题和Palette 使用Palette来...

  • Android 上的调色板 —— Palette

    Android 上有一个比较短小精悍的库 —— Palette,整个库只有Palette、Target和Color...

  • Android Palette

    作用: Palette:可以在一张图片里面分析出一些色彩特性:主色调、鲜艳的颜色、柔和颜色等等 使用方法 1.引入...

  • Palette

    Android Palette Palette 可以从一张图片中提取颜色,我们可以把提取的颜色融入到App UI中...

  • Palette

    Palette 单词本意是调色板的意思,所以在Android中Palette肯定会与颜色有关,它在作用是根据当前图...

  • Android Palette 介绍

    Palette是一个可以从图片(Bitmap)中提取颜色的帮助类,可以使UI更加美观,根据图片动态的显示相应的颜色...

网友评论

    本文标题:Android Palette

    本文链接:https://www.haomeiwen.com/subject/ppiedqtx.html