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. Mac OS 查看端口和杀死进程

    查看sudo lsof -i:port (端口号) sudo lsof -i:9501 COMMAND PID USER FD TYPE DEVICESIZE/OFF NODE NAME php 77 ...

  2. Redis SCAN命令实现有限保证的原理

    SCAN命令可以为用户保证:从完整遍历开始直到完整遍历结束期间,一直存在于数据集内的所有元素都会被完整遍历返回,但是同一个元素可能会被返回多次.如果一个元素是在迭代过程中被添加到数据集的,又或者是在迭 ...

  3. MySQL对数据表已有表进行分区表

    原文:https://blog.51cto.com/13675040/2114580 1.由于数据量较大,对现有的表进行分区 操作方式.可以使用ALTER TABLE来进行更改表为分区表,这个操作会创 ...

  4. Ubuntu不能使用passwd的--stdin的解决办法

    转载请注明来源https://www.cnblogs.com/sogeisetsu/p/11397648.html Ubuntu不能使用passwd的--stdin的解决办法 可以使用chpasswd ...

  5. Linux-导入已安装的Linux系统

    之前在安装过一个Linux系统,由于重装电脑需要将之前安装的系统重新移动到VMWare中,让Linux系统能够重新运行起来,这样也省去了每次重新安装系统的麻烦. 废话不多说,咱们直接看是如何做? 1) ...

  6. 【PHP】系统部署

    1.MySql数据库,单独创建用户和数据库 使用MySql-Front导入,避免使用Navicat导入 2.httpd-vhosts.conf配置 文件位于:D:\Xampp\apache\conf\ ...

  7. wordpress调用置顶文章sticky_posts的三种方法

    有时我们在开发wordpress时需要调用置顶文章sticky_posts,怎么调用呢?几种写法,有用到query_post的,有用到WP_Query,也有用到is_sticky(),下面随ytkah ...

  8. c#接口interface学习

    好久没学习C#了,上次已经学习到了接口这块,感觉有点不太好理解,因此重新学习,在vs上面运行了,本来不想写博客的,但是正好看到网上有人说,写博客可以加深印象,因此,写吧. 下面是菜鸟教程的实例 usi ...

  9. 如何在你的springboot(cloud)项目中引入我的github上的jar仓库呢?

    1. 将此标签内容放到pom.xml仅次于project标签下 <repositories> <repository> <id>github</id> ...

  10. ABP 01 项目的基本运行

    原文:https://www.cnblogs.com/ldybyz/p/8441084.html 照着这篇文章弄 一般是没有什么问题的 记录一下我出现的问题,大多是没有仔细看文章. 1.无法迁移数据库 ...