【UI】Palette的使用API
来源:互联网 发布:浙江师范大学数据库 编辑:程序博客网 时间:2024/06/07 03:35
1、Palette的使用:
引入v7里面的一个单独项目Palette,android.support.v7.graphics.Palette;
Palette:可以在一张图片里面分析出一些色彩特性:主色调、鲜艳的颜色、柔和颜色等等……
public class MainActivity extends AppCompatActivity { private ImageView iv; private TextView tv_title; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); iv = (ImageView)findViewById(R.id.iv); tv_title = (TextView)findViewById(R.id.tv_title); final TextView tv1 = (TextView)findViewById(R.id.tv1); final TextView tv2 = (TextView)findViewById(R.id.tv2); final TextView tv3 = (TextView)findViewById(R.id.tv3); final TextView tv4 = (TextView)findViewById(R.id.tv4); final TextView tv5 = (TextView)findViewById(R.id.tv5); final TextView tv6 = (TextView)findViewById(R.id.tv6); 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); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); }}
阅读全文
0 0
- 【UI】Palette的使用API
- Palette的使用
- Palette的使用
- Palette的简单使用
- Palette调色板的使用
- Palette的使用
- Palette的简单使用
- 使用 Palette 让你的 UI 色彩与内容更贴合
- Android Palette 调色板 的使用
- [MD学习]使用ActionBar+DrawableLayout+Palette打造侧滑UI
- 安卓Palette(颜色拾取)的使用
- Android 5.0 Palette的使用小结
- Android RecyclerView、CardView、Palette的使用
- 使用Palette提取图片的颜色信息
- Android 5.X Color Palette的使用
- palette调色板初级使用
- android Palette使用详解
- Android Palette使用详解
- 程序设计基础—运算符知识点
- 刷子表
- 在使用 Spring Security 的 Remember Me 记住密码功能时遇到的问题和解决方法
- Qt下载路径
- 第一节
- 【UI】Palette的使用API
- HTML-JavaScript-登录网页及验证
- box-sizing&&0utline属性
- IOException parsing XML document from class path resource resource [com/zj/spring01/helloworld/appli
- 利用指向调用函数输出两个数中的较大者
- 基于Android、ios平台,支持接口开发的移动端车牌识别技术
- TensorFlow学习--tensorflow图像处理--添加标注框
- 日常手残
- [深度学习]Ubuntu16.04 + GTX 1050 + cuda8.0 + cuDNN5.1 + caffe安装详解