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 ...
随机推荐
- Python 操作 MySQL 数据库
使用示例: import pymysql #python3 conn=pymysql.connect(host="localhost",port=3306,user="r ...
- Gateway-Worker启动失败或者启动无法正常使用的几种方法
Workerman是一款开源高性能异步PHP socket即时通讯框架.支持高并发,超高稳定性,被广泛的用于手机app.移动通讯,微信小程序,手游服务端.网络游戏.PHP聊天室.硬件通讯.智能家居.车 ...
- Mybatis如何插入空字段
出现异常:SQLException : 无效的类型: 1111 使用Mybatis插入一条记录,某字段设为null,出错 尝试将空的mgr属性插入到数据库,解决办法: 添加setting属性jdbcT ...
- BBS之文章详情页搭建
博客评论相关 博客文章详情页搭建 {% extends 'base.html' %} {% block css %} <style> #div_digg { float: right; m ...
- 网络文件系统-NFS
1. 什么是NFS NFS是 Network File System 的缩写,即网络文件系统.一种使用于分散式文件系统的协议,有Sun公司开发,于1984年向外公布.功能是通过网络让不同的机器.不同的 ...
- docker(ubuntu)中安装cron运行crontab定时任务
1.安装cron apt-get install cron 设置crontab定时任务 crontab -e */ * * * * /usr/bin/python /python/asch-check ...
- 性能测试基础---测试流程,LR安装
·性能测试流程详解: 一般来说,性能测试通常可以分为以下过程: ·前期分析.测试计划.测试方案.测试环境的搭建.测试数据的准备.测试脚本的开发.测试场景的设计.测试场景的实现和执行.资源的监控.分析结 ...
- Exploit Kit——hacker入侵web,某iframe中将加载RIG EK登录页面,最终下载并执行Monero矿工
RIG Exploit Kit使用PROPagate注入技术传播Monero Miner from:https://www.4hou.com/technology/12310.html 导语:Fire ...
- oracle-shell备份
获取PAH写入脚本 cat /home/oracle/.bash_profile 编写脚本oadbbak.sh PATH backuptime=`date +%Y%m%d%H%M%S` exp use ...
- KVM-安装windows
硬盘.网卡选择vitio 虚拟机配置2个cd-rom,分别挂载系统iso与virtio-win 开始安装无法识别硬盘,加载光驱驱动 安装完成进入系统之后,设备管理器添加驱动,识别设备