HSBImageView--android--可以设置HSB值的imageview
package guide.yunji.com.guide.view; import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable;
import android.support.v7.widget.AppCompatImageView;
import android.util.AttributeSet; import guide.yunji.com.guide.R; public class HSBImageView extends AppCompatImageView {
private static ColorMatrix colorMatrix = new ColorMatrix();
/**
* 色调,改变颜色
*/
private static ColorMatrix hueMatrix = new ColorMatrix();
/**
* 饱和度,改变颜色的纯度
*/
private static ColorMatrix saturationMatrix = new ColorMatrix();
/**
* 亮度,控制明暗
*/
private static ColorMatrix brightnessMatrix = new ColorMatrix(); private float hueValue = 0f;
private float saturationValue = 1f;
private float brightnessValue = 1f; public HSBImageView(Context context) {
super(context);
} public HSBImageView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
} public HSBImageView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.HSBImageView);
hueValue = array.getFloat(R.styleable.HSBImageView_hueValue, 0f);
saturationValue = array.getFloat(R.styleable.HSBImageView_saturationValue, 1f);
brightnessValue = array.getFloat(R.styleable.HSBImageView_brightnessValue, 1f);
array.recycle(); //释放资源
setHSB(hueValue, saturationValue, brightnessValue);
} @Override
public void setImageResource(int resId) {
super.setImageResource(resId);
setHSB(hueValue, saturationValue, brightnessValue);
} private void setHSB(float hueValue, float saturationValue, float brightnessValue) {
//设置色相,为0°和360的时候相当于原图
hueMatrix.reset();
hueMatrix.setRotate(0, hueValue);
hueMatrix.setRotate(1, hueValue);
hueMatrix.setRotate(2, hueValue); //设置饱和度,为1的时候相当于原图
saturationMatrix.reset();
saturationMatrix.setSaturation(saturationValue); //亮度,为1的时候相当于原图
brightnessMatrix.reset();
brightnessMatrix.setScale(brightnessValue, brightnessValue, brightnessValue, 1); //将上面三种效果和选中的模式混合在一起
colorMatrix.reset();
colorMatrix.postConcat(hueMatrix);
colorMatrix.postConcat(saturationMatrix);
colorMatrix.postConcat(brightnessMatrix); setColorFilter(new ColorMatrixColorFilter(colorMatrix));
}
}
<declare-styleable name="HSBImageView">
<!--name:自定义属性名,format:自定义属性数据类型-->
<attr name="hueValue" format="float"></attr>
<attr name="saturationValue" format="float"></attr>
<attr name="brightnessValue" format="float"></attr>
</declare-styleable>
<guide.yunji.com.guide.view.HSBImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:saturationValue="1.8"
app:brightnessValue="1.0"
android:id="@+id/shade"/>
可以设置HSB值的imageview
HSBImageView--android--可以设置HSB值的imageview的更多相关文章
- android 动态设置TextView值,例:金额添加
一说到动态递增设置TextView值,非常多人应该立即就想到起个线程,让后在线程中睡眠指定时间,使用handler发送消息更新TextView值! 这样是实现了动态递增设置TextView值可是效率不 ...
- android 动态设置TextView值,例:金额增加
一说到动态递增设置TextView值,很多人应该马上就想到起个线程,让后在线程中睡眠指定时间,使用handler发送消息更新TextView值! 这样是实现了动态递增设置TextView值但是效率不咋 ...
- [android] setOnTouchEvent 设置返回值为true 和 false的区别
今天在做自定义的可选文本的 TextView 类时,用到了 View 类的 setOnTouchListener(OnTouchListener l)事件监听,在构造 OnTouchListener ...
- Android 设置alpha值来制作透明与渐变效果的实例
Android系统支持的颜色是由4个值组成的,前3个为RGB,也就是我们常说的三原色(红.绿.蓝),最后一个值是A,也就是Alpha.这4个值都在0~255之间.颜色值越小,表示该颜色越淡,颜色值越大 ...
- android中,如果使用imageButton可以在drawable 中设置一个selector,但是imageView设置不起作用
android中,如果使用imageButton可以在drawable 中设置一个selector,但是imageView设置不起作用,只要把Imageview的src给去掉就成了,src捕获了bac ...
- Android控件设置半透明+EditText设置默认值+ 控件居中
Android控件设置半透明 效果 代码: android:background="#50FFFFFF" 50表示50%透明 Android:EditText设置默认值 andro ...
- Android中设置TextView的颜色setTextColor
tv.setTextColor(Color.parseColor("#FFFFFF")); tv.setTextColor(Color.WHITE); tv.setTextColo ...
- Android RadioGroup设置默认选中项
今天有人问.Android 里面 RadioGroup里面有两个RadioButton怎么设置默认值? 第一个RadioButton设置 android:checked="true" ...
- Browser设置UA值
SWE Browser中的OptionMenu是Controller通过onKeyDown监听KEYCODE_MENU来显示的 public boolean onKeyDown(int keyCode ...
随机推荐
- Java集合学习(3):HashSet
一.概述 HashSet实现Set接口,由哈希表(实际上是一个HashMap实例)支持.它不保证set 的迭代顺序:特别是它不保证该顺序恒久不变.此类允许使用null元素. HashSet是基于Has ...
- Solr基础理论【倒排索引,模糊查询】
一.简介 现有的许多不同类型 的技术系统,如关系型数据库.键值存储.操作磁盘文件的map-reduce[映射-规约]引擎.图数据库等,都是为了帮助用户解决颇具挑战性的数据存储与检索问题而设计的.而搜索 ...
- C# 方法执行超时处理
封装了一个方法,用于处理一些需要判断是否执行超时了的操作 internal static T TimeoutCheck<T>(int ms, Func<T> func) { v ...
- 【Python】列表推导式
1. 列表推导式 list1 = [1, 3, 5, 6, 8] list2 = [x * 2 for x in list1] print(list2) # [2, 6, 10, 12, 16]
- Git回滚代码
回滚命令: 1.回退到上个版本 $ git reset --hard HEAD^ 2.回退到前2次提交之前,以此类推,回退到n次提交之前 $ git reset --hard HEAD~2 3.退到/ ...
- 性能测试基础---测试流程,LR安装
·性能测试流程详解: 一般来说,性能测试通常可以分为以下过程: ·前期分析.测试计划.测试方案.测试环境的搭建.测试数据的准备.测试脚本的开发.测试场景的设计.测试场景的实现和执行.资源的监控.分析结 ...
- 【P1889】SOLDIERS (中位数)
题目描述 在一个划分成网格的操场上, n个士兵散乱地站在网格点上.由整数 坐标 (x,y) 表示.士兵们可以沿网格边上.下左右移动一步,但在同时刻任一网格点上只能有名士兵.按照军官的命令,们要整齐地列 ...
- cmds jdbc连接写法
格式一: Oracle JDBC Thin using a ServiceName: jdbc:oracle:thin:@//<host>:<port>/<servic ...
- wordpress定时发布失败Missed Schedule解决方法
今天一位客户的网站设置了文章定时发布但却没有发布成功,提示Missed Schedule错误,把所有的插件都暂停了再设置定时发布也不行,那就只能寻找其他的解决方案了.ytkah查看一下有没相关修复插件 ...
- [Schematics] 2. EJS
Schematices using EJS as template language. template: <%# This will not appear in the generated o ...