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. tensorflow提示:No module named ''tensorflow.python.eager".

        版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/qq_27921205/articl ...

  2. mybatis update 返回值

    mybatis sql: <update id="test" parameterType="map"> update test_0731 set n ...

  3. swipe滑动操作

    1.swipe() 滑动用法 swipe(self, start_x, start_y, end_x, end_y, duration=None) :Args: - start_x - 开始滑动的x坐 ...

  4. 关于Ubuntu下is not in the sudoers file解决方法

    当我在postgres用户下去执行sudo vim demo.sql需要用管理员权限运行时,并且输入本用户的密码,但是输入之后提示如下: postgers is not in the sudoers ...

  5. jmeter 实现登录参数化

    业务场景 在测试过程中,一般需要模拟不同的用户登录,这样压测的数据比较平均,也能更好的模拟真实的压力情况. 如果使用同一个用户账号进行测试,那么比如在查询代办的时候,此人的待办太多,也不符合实际的情况 ...

  6. Odoo定时任务(自动任务)

    转载请注明原文地址:https://www.cnblogs.com/ygj0930/p/10826270.html  一:定时任务模型 Odoo中内置了一个定时任务模型  ir.cron ,它定义了一 ...

  7. python正则表达式(6)--split、sub、escape方法

    1.re.split 语法: re.split(pattern, string[, maxsplit=0, flags=0]) 参数: pattern    匹配的正则表达式 string      ...

  8. git---如何解决The authenticity of host can't be established.

    新生成密钥的时候,git clone或者push的时候,可能会报这样的错误: ``` The authenticity of host 'gitee.com (xxx.xxx.xxx.xxx)' ca ...

  9. appuploader 使用

    mac 使用 Jar Lanucher.app 打开 解压后的 appuploader.jar 文件,即可启动 appuploader. 内容 网址 官方网站 http://www.appupload ...

  10. live-pusher属性值的改变

    例如:组件推流过程中,切换前后摄像头时,要改变mirror的值并使其生效: LivePusherContext = wx.createLivePusherContext() 1. LivePusher ...