当前位置: 首页>>代码示例>>Java>>正文


Java Palette.from方法代码示例

本文整理汇总了Java中android.support.v7.graphics.Palette.from方法的典型用法代码示例。如果您正苦于以下问题:Java Palette.from方法的具体用法?Java Palette.from怎么用?Java Palette.from使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.support.v7.graphics.Palette的用法示例。


在下文中一共展示了Palette.from方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: changeColor

import android.support.v7.graphics.Palette; //导入方法依赖的package包/类
/**
 * 改变各部分的颜色
 * @param position 下标
 */
private void changeColor(final int position) {
    Palette.Swatch swatch = mSwatchMap.get(position);
    if (swatch != null){
        setColor(swatch);//设置颜色
        return;
    }
    // 用来提取颜色的Bitmap
    Bitmap bitmap = BitmapFactory.decodeResource(getResources(),mImgResources[position]);
    // Palette的部分
    Palette.Builder builder = Palette.from(bitmap);
    builder.generate(new Palette.PaletteAsyncListener() {
        @Override
        public void onGenerated(Palette palette) {
            //获取到充满活力的样本
            Palette.Swatch vibrant = palette.getVibrantSwatch();
            setColor(vibrant);//设置颜色
            mSwatchMap.put(position,vibrant);//保存对应位置的样本对象
        }
    });
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:25,代码来源:PaletteActivity2.java

示例2: pickPicColors

import android.support.v7.graphics.Palette; //导入方法依赖的package包/类
public void pickPicColors() {
        Bitmap bitmap = ((BitmapDrawable) mIvPic.getDrawable()).getBitmap();
        Palette.Builder builder = Palette.from(bitmap);
        builder.generate(new Palette.PaletteAsyncListener() {
            @Override
            public void onGenerated(Palette palette) {
                //提取有活力的颜色
                int vibrantColor = palette.getVibrantColor(Color.RED);
                mTvVibrant.setBackgroundColor(vibrantColor);

                //提取有活力的 亮色
                int lightVibrantColor = palette.getLightVibrantColor(Color.RED);
                mTvLightVibrant.setBackgroundColor(lightVibrantColor);

                //提取有活力的 暗色
                int darkVibrantColor = palette.getDarkVibrantColor(Color.RED);
                mTvDarkVibrant.setBackgroundColor(darkVibrantColor);

                //提取柔和的颜色
                int mutedColor = palette.getMutedColor(Color.RED);
                mTvMuted.setBackgroundColor(mutedColor);

                //提取柔和的亮色
                int lightMutedColor = palette.getLightMutedColor(Color.RED);
                mTvLightMuted.setBackgroundColor(lightMutedColor);

                //提取柔和的暗色
                int darkMutedColor = palette.getDarkMutedColor(Color.RED);
                mTvDarkMuted.setBackgroundColor(darkMutedColor);


                Palette.Swatch vibrantSwatch = palette.getVibrantSwatch();//获取有活力的颜色样本
                Palette.Swatch lightVibrantSwatch = palette.getLightVibrantSwatch();//获取有活力 亮色的样本
                Palette.Swatch drakVibrantSwatch = palette.getDarkVibrantSwatch();//获取有活力 暗色的样本

                Palette.Swatch mutedSwatch = palette.getMutedSwatch();//获取柔和的颜色样本
                Palette.Swatch lightMutedSwatch = palette.getLightMutedSwatch();//获取柔和 亮色的样本
                Palette.Swatch darkMutedSwatch = palette.getDarkMutedSwatch();//获取柔和 暗色的样本

//                int rgb = vibrantSwatch.getRgb();//获取对应样本的rgb
//                float[] hsl = vibrantSwatch.getHsl();//获取hsl颜色
//                int population = vibrantSwatch.getPopulation();//获取像素的数量
//                int titleTextColor = vibrantSwatch.getTitleTextColor();//获取适合标题文字的颜色
//                int bodyTextColor = vibrantSwatch.getBodyTextColor();//获取适配内容文字的颜色


                //获取适合标题文字的颜色
                int titleTextColor = drakVibrantSwatch.getTitleTextColor();
                mTvTitle.setTextColor(titleTextColor);
                ;
                //获取适合内容文字的颜色
                int bodyTextColor = drakVibrantSwatch.getBodyTextColor();
                mTvBody.setTextColor(bodyTextColor);

            }
        });
    }
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:58,代码来源:PaletteActivity1.java

示例3: onCreate

import android.support.v7.graphics.Palette; //导入方法依赖的package包/类
@Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_palette);
        mIvPic = (ImageView) findViewById(R.id.ivPic);
        mTvBody = (TextView) findViewById(R.id.tvBody);
        mTvTitle = (TextView) findViewById(R.id.tvTitle);
        mTvDarkMutedColor = (TextView) findViewById(R.id.tvDarkMutedColor);
        mTvLightMutedColor = (TextView) findViewById(R.id.tvLightMutedColor);
        mTvDarkVibrantColor = (TextView) findViewById(R.id.tvDarkVibrantColor);
        mTvLightVibrantColor = (TextView) findViewById(R.id.tvLightVibrantColor);
        mTvMutedColor = (TextView) findViewById(R.id.tvMutedColor);
        mTvVibrantColor = (TextView) findViewById(R.id.tvVibrantColor);

        BitmapDrawable drawable = (BitmapDrawable) mIvPic.getDrawable();
        Bitmap bitmap = drawable.getBitmap();

        Palette.Builder builder = Palette.from(bitmap);
        builder.maximumColorCount(32); // 构建Palette时使用的最大颜色数,默认是16,风景图推荐取值8-16,人脸图像推荐取值24-32(值越大,花费的时间越长,可选择的色彩越多)
//                .setRegion(0, 0, bitmap.getWidth() - 1, bitmap.getHeight()) // 设置Palette颜色分析的图像区域
//                .addFilter(new Palette.Filter() { // 设置过滤器来过滤不需要的颜色(目前还不清楚怎么用,网上也找不到任何教程及代码,无从学习~)
//                    @Override
//                    public boolean isAllowed(int rgb, float[] hsl) {
//                        return false;
//                    }
//                })
//                .clearRegion()
//                .clearFilters();

        builder.generate(new Palette.PaletteAsyncListener() {
            @Override
            public void onGenerated(Palette palette) {
                // 暗、柔和
                int darkMutedColor = palette.getDarkMutedColor(Color.BLACK);
                // 亮、柔和
                int lightMutedColor = palette.getLightMutedColor(Color.BLACK);
                // 暗、鲜艳
                int darkVibrantColor = palette.getDarkVibrantColor(Color.BLACK);
                // 亮、鲜艳
                int lightVibrantColor = palette.getLightVibrantColor(Color.BLACK);
                // 柔和
                int mutedColor = palette.getMutedColor(Color.BLACK);
                // 鲜艳
                int vibrantColor = palette.getVibrantColor(Color.BLACK);

                // 获取某种色调的样品(这里指柔和的暗色)
                Palette.Swatch darkMutedSwatch = palette.getDarkMutedSwatch();
                // 获取图片的整体颜色rgb混合值---主色调
                int rgb = darkMutedSwatch.getRgb();
                // 获取图片中间的文字颜色
                int bodyTextColor = darkMutedSwatch.getBodyTextColor();
                // 获取作为标题的颜色(有一定的和图片的对比度的颜色值)
                int titleTextColor = darkMutedSwatch.getTitleTextColor();
                // 颜色向量
                float[] hsl = darkMutedSwatch.getHsl();
                // 分析该颜色在图片中所占像素值
                int population = darkMutedSwatch.getPopulation();

                mTvBody.setBackgroundColor(generateTransparentColor(0.2f, rgb));
                mTvBody.setTextColor(bodyTextColor);
                mTvTitle.setBackgroundColor(generateTransparentColor(0.6f, rgb));
                mTvTitle.setTextColor(titleTextColor);

                mTvDarkMutedColor.setBackgroundColor(darkMutedColor);
                mTvLightMutedColor.setBackgroundColor(lightMutedColor);
                mTvDarkVibrantColor.setBackgroundColor(darkVibrantColor);
                mTvLightVibrantColor.setBackgroundColor(lightVibrantColor);
                mTvMutedColor.setBackgroundColor(mutedColor);
                mTvVibrantColor.setBackgroundColor(vibrantColor);
            }
        });
    }
 
开发者ID:GitLqr,项目名称:MaterialDesignDemo,代码行数:73,代码来源:PaletteActivity.java

示例4: onResourceReady

import android.support.v7.graphics.Palette; //导入方法依赖的package包/类
/**
 * Called when a load completes successfully, immediately after
 * {@link Target#onResourceReady(Object, GlideAnimation)}.
 *
 * @param resource          The resource that was loaded for the target.
 * @param model             The specific model that was used to load the image.
 * @param target            The target the model was loaded into.
 * @param isFromMemoryCache True if the load completed synchronously (useful for determining whether or not to
 *                          animate)
 * @param isFirstResource   True if this is the first resource to in this load to be loaded into the target. For
 *                          example when loading a thumbnail and a fullsize image, this will be true for the first
 *                          image to load and false for the second.
 * @return True if the listener has handled setting the resource on the target (including any animations), false to
 * allow Glide's request to update the target (again including animations).
 */
@Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
    try {
        Palette.Builder mBuilder = Palette.from(((GlideBitmapDrawable) resource.getCurrent()).getBitmap());
        mBuilder.generate(this);
    } catch (ClassCastException ex) {
        ex.printStackTrace();
    }
    return false;
}
 
开发者ID:wax911,项目名称:anitrend-app,代码行数:26,代码来源:PreviewImageAdapter.java


注:本文中的android.support.v7.graphics.Palette.from方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。