Palette调色板
2017-02-17 13:37
405 查看
一、什么是Palette
1.Palette:可以在一张图片里面分析出一些色彩特性:主色调、鲜艳的颜色、柔和颜色等等……比如:
引入v7里面的一个单独项目Palette:
android.support.v7.graphics.Palette;
二、使用
将某个颜色值加入透明度:
也可以使用ColorUtils的方法
1.Palette:可以在一张图片里面分析出一些色彩特性:主色调、鲜艳的颜色、柔和颜色等等……比如:
引入v7里面的一个单独项目Palette:
android.support.v7.graphics.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(); tv_title.setBackgroundColor(getTranslucentColor(0.6f,rgb)); tv_title.setTextColor(titleTextColor); tv1.setBackgroundColor(darkMutedColor); tv1.setText("darkMutedColor"); tv2.setBackgroundColor(lightMutedColor); tv2.setText("lightMutedColor"); tv3.setBackgroundColor(darkVibrantColor); tv3.setText("darkVibrantColor"); tv4.setBackgroundColor(lightVibrantColor); tv4.setText("lightVibrantColor"); tv5.setBackgroundColor(mutedColor); tv5.setText("mutedColor"); tv6.setBackgroundColor(vibrantColor); tv6.setText("vibrantColor"); } });
将某个颜色值加入透明度:
/** * 1101 0111 1000 1011 * 1111 1111 * 1000 1011 */ 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); }
也可以使用ColorUtils的方法
相关文章推荐
- Android Study Material Design 八 之 玩转Palette调色板
- 自定义(手动调整).net中图像的调色板(How to adjust (customize) image's palette in .net?)
- Qt学习笔记外观篇(一):QPalette调色板
- android Palette调色板的使用方法
- Windows位图(Bitmap)和调色板(Palette)
- Palette(调色板)
- android5.x之Palette调色板
- Qt 设置背景图片3种方法(三种方法:QPalette调色板,paintEvent,QSS)
- Android Palette 调色板 的使用
- Pyqt 设置 背景颜色和背景图片、 QPalette 调色板 与QPainter 画板区别 、 不规则图片
- Material Design UI Widgets —— Palette 调色板
- Android5.0的Palette(调色板)、视图阴影、着色和裁剪介绍
- (三十一)Qt中的调色板QPalette
- Qt编程18:Qt调色板QPalette的使用
- Android学习之5.0三姐妹调色板palette的使用
- Qt学习12——调色板QPalette
- Qt编程18:Qt调色板QPalette的使用
- Material Design设计之Palette调色板
- 使用调色板Palette在背景图中取色
- 图像处理里面调色板(Palette)是什么意思?