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的更多相关文章

  1. android 动态设置TextView值,例:金额添加

    一说到动态递增设置TextView值,非常多人应该立即就想到起个线程,让后在线程中睡眠指定时间,使用handler发送消息更新TextView值! 这样是实现了动态递增设置TextView值可是效率不 ...

  2. android 动态设置TextView值,例:金额增加

    一说到动态递增设置TextView值,很多人应该马上就想到起个线程,让后在线程中睡眠指定时间,使用handler发送消息更新TextView值! 这样是实现了动态递增设置TextView值但是效率不咋 ...

  3. [android] setOnTouchEvent 设置返回值为true 和 false的区别

    今天在做自定义的可选文本的 TextView 类时,用到了 View 类的 setOnTouchListener(OnTouchListener l)事件监听,在构造 OnTouchListener ...

  4. Android 设置alpha值来制作透明与渐变效果的实例

    Android系统支持的颜色是由4个值组成的,前3个为RGB,也就是我们常说的三原色(红.绿.蓝),最后一个值是A,也就是Alpha.这4个值都在0~255之间.颜色值越小,表示该颜色越淡,颜色值越大 ...

  5. android中,如果使用imageButton可以在drawable 中设置一个selector,但是imageView设置不起作用

    android中,如果使用imageButton可以在drawable 中设置一个selector,但是imageView设置不起作用,只要把Imageview的src给去掉就成了,src捕获了bac ...

  6. Android控件设置半透明+EditText设置默认值+ 控件居中

    Android控件设置半透明 效果 代码: android:background="#50FFFFFF" 50表示50%透明 Android:EditText设置默认值 andro ...

  7. Android中设置TextView的颜色setTextColor

    tv.setTextColor(Color.parseColor("#FFFFFF")); tv.setTextColor(Color.WHITE); tv.setTextColo ...

  8. Android RadioGroup设置默认选中项

    今天有人问.Android 里面 RadioGroup里面有两个RadioButton怎么设置默认值? 第一个RadioButton设置 android:checked="true" ...

  9. Browser设置UA值

    SWE Browser中的OptionMenu是Controller通过onKeyDown监听KEYCODE_MENU来显示的 public boolean onKeyDown(int keyCode ...

随机推荐

  1. 没有用到React,为什么我需要import引入React?

    没有用到React,为什么我需要import引入React? 本质上来说JSX是React.createElement(component, props, ...children)方法的语法糖. 所以 ...

  2. Unity编辑器扩展中,使用Unity自带的GUIStyle

    在进行编辑器扩展时,创建组件的方法一般都会提供GUIStyle参数,可以让我们自定义样式.修改背景图,字体大小,颜色等等. 比如,创建Button组件的方法:public static bool Bu ...

  3. AR自动开票主程序导入发票的时候,出现错误提示''不能获取汇款地址''

    问题:AR自动开票主程序,出现错误不能获取汇款地址 解决:AR>设置-打印-汇入地址,汇入地址要增加此客户地点对应的国家:

  4. Omapl138中AIS文件分析(参照Using the OMAP-L138 Bootloader)(转)

    Omapl138中AIS文件分析(参照Using the OMAP-L138 Bootloader) 转载链接:https://blog.csdn.net/qq_40788950/article/de ...

  5. mysql 触发器、流程控制、事务等

    视图 触发器 事务 存储过程 内置函数 流程控制 索引 视图 1.什么是视图 ​ 视图就是通过查询得到一张虚拟表,然后保存下来,下次直接使用即可 2.为什么要用视图 ​ 如果要频繁使用一张虚拟表,可以 ...

  6. springboot 单元测试 指定启动类

    问题 在做单元测试时,写了一个工具类,用于注入spring的上下文. public class AppBeanUtil implements ApplicationContextAware { pri ...

  7. PHP操作MYSQL--PDO

    感觉比直接弄SQL语句高级,但还不到ORM的封装. 一步一步进化. app.json { "db": { "user": "root", & ...

  8. 2.创建NHibernateHelper帮助类,生成sessionFactory

    接上一篇文章 使用FluentNHibemate 操作数据库,添加映射到数据库 http://www.cnblogs.com/fzxiaoyi/p/8443586.html 在Model文件下再创建个 ...

  9. can总线的远程帧(遥控帧)—说的很形象

    所谓“远程帧”是一个传统翻译上的误区.Remote Frame实际上它的意义是“遥控帧”,发起方发起特定ID的远程帧,并且只发送ID部分,那么与其ID相符的终端设备就有义务在后半段的数据部分接管总线控 ...

  10. Easy-Mock模拟get接口和post接口实例

    1.先创建项目,再新建接口 创建项目入口:首页右下角 + 按钮 创建接口入口如下图: 关于mock的语法这里不做说明,可查看mock.js官方查看更详情的资料. 小tip:在Easy-Mock里面支持 ...