android 5.x—Palette图片取色调
来源:互联网 发布:软件开发是什么工作 编辑:程序博客网 时间:2024/05/17 05:18
在android的版本更新历程中,UI美观越发成为Google发展的重心。Material Design是谷歌推出的全新的设计语言规范,旨在为手机、平板、台式机和“其他平台”提供更为一致、更广泛的“外观和感觉“。
在android 5.x中提出了Palette提取图片颜色的概念,这样便可以把色值付给ActionBar,其他View,让整个界面保持统一的色调。
使用Palette需要引入库com.android.support:palette-v7:23.2.0(版本号可能不相同)。然后传递一个Bitmap对象给Palette,并调用Palette.generate()静态方法或者Palette.generateAsync()方法创建一个Palette对象。
// Synchronous methods.// --------------------------------// These should be used when you have access to the underlying image loading thread.// Picasso allows this through a Transformation. For other libraries, YMMV.// Uses the default palette size (16).Palette p = Palette.generate(bitmap);// Allows you to specify the maximum palette size, in this case 24.Palette p = Palette.generate(bitmap, 24);// Asynchronous methods// --------------------------------// This is the quick and easy integration path. Internally uses an AsyncTask so// this may not be optimal (since you're dipping in and out of threads)// Uses the default palette size (16).Palette.generateAsync(bitmap, new Palette.PaletteAsyncListener() { @Override public void onGenerated(Palette palette) { // Here's your generated palette }});// Allows you to specify the maximum palette size, in this case 24.Palette.generateAsync(bitmap, 24, new Palette.PaletteAsyncListener() { @Override public void onGenerated(Palette palette) { // Here's your generated palette }});
然后可以得到6中采集的颜色样本(Swatch),
// 充满活力的色调Palette.Swatch vibrantSwatch = palette.getVibrantSwatch();// 充满活力的亮色调Palette.Swatch lightVibrantSwatch = palette.getLightVibrantSwatch();// 充满活力的暗色调Palette.Swatch darkVibrantSwatch = palette.getDarkVibrantSwatch();// 柔和的色调Palette.Swatch mutedSwatch = palette.getMutedSwatch();// 柔和的亮色调Palette.Swatch lightMuteSwatch = palette.getLightMutedSwatch();// 柔和的暗色调Palette.Swatch darkMutedSwatch = palette.getDarkMutedSwatch();
需要注意的是,上述获取的Palette.Swatch对象可能为null,因此,在使用该对象时,必须对null值判断。
Swatch有如下方法:
// the amount of pixels which this swatch representsgetPopulation();// the RGB value of this colorgetRgb();// the HSL value of this colorgetHsl();// the RGB value of a text color which can be displayed on top of this colorgetBodyTextColor();// the RGB value of a text color which can be displayed on top of this colorgetTitleTextColor();
讲了这么多,现在看看使用的效果图:
demo下载链接
0 0
- android 5.x—Palette图片取色调
- Android使用Palette获取图片主色调
- Android 使用Palette获取Gallery图片主色调
- Android Lollipop:使用Palette抽取图片主色调
- android 5.x设置actionBar色调
- Android 5.x之Toolbar和Palette
- Android 5.X Color Palette的使用
- Android 5.x新特性之利用Palette获取图片的主题色
- Android 5.X 新特性详解(一)——主题、Palette、阴影、着色和裁剪
- Android 5.x--使用Material Theme加Palette
- Android 5.x--使用Material Theme加Palette
- Android 5.x--使用Material Theme加Palette
- Android 5.X之Ripple,Palette的详解
- Android 5.x新特性之-Palette类
- android Palette 自动识别图片颜色
- iOS图片精确提取主色调算法iOS-Palette(附源码)
- android中图片色调识别探究
- Android 图片切换各种色调变化
- css3 实现3D导航栏
- svn
- WinPython-64-2.7安装MySQLdb包
- hdu ztr loves lucky numbers (最小的但不小于n的幸运数字是多少,幸运数字只含4和7,且4的个数等于7的个数)
- Leetcode:62. Unique Paths
- android 5.x—Palette图片取色调
- 4.图像标记<img>
- hdu 5675 ztr loves math【思维】
- 剑指offer(61):对称的二叉树
- TeamTalk---服务端架构
- 【HDU2089】不要62【数位DP】【记忆化搜索】
- 工厂方法模式
- android UI(1)-PopupWindow
- 74、JDK安装与环境变量配置