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 ...
随机推荐
- Django 配置mysql遇到问题(一)
问题一: django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have ...
- MySql操作命令创建学生管理系统
1.创建学生管理系统数据库xscj create detabase 数据库名: 2.打开数据库 use 数据库名: //创建数据库之后,该数据库不会自动成为当前数据库需要用use来指定 3.创建表名 ...
- web模拟终端 --使用shellinabox
关于shellinabox ShellInABox实现了一个Web服务器,可以将任意命令行工具导出到基于Web的终端仿真器.任何支持JavaScript和CSS的Web浏览器都可以访问此模拟器,并且不 ...
- 性能测试基础---LR参数化相关
性能测试脚本的增强:·参数化·关联·事务·检查点·思考时间·集合点 ·参数化:模拟不同用户的不同请求. ·为什么要做参数化? ·功能:通常来说,系统的某些业务数据具有唯一性的要求. ·性能:一般来说, ...
- php长连接和短连接区别
短连接 连接->传输数据->关闭连接(推荐学习:PHP编程从入门到精通) 比如HTTP是无状态的的短链接,浏览器和服务器每进行一次HTTP操作,就建立一次连接,但任务结束就中断连接. 具体 ...
- python应用-n颗骰子的和出现的次数
from random import randint def roll_dice(n): total=0 for _ in range (n): num=randint(1,6) total+=num ...
- 51Nod1686 第K大区间 和 NOI2016 区间
谈一下尺取法的经典题. 第K大区间 定义一个区间的值为其众数出现的次数. 现给出n个数,求将所有区间的值排序后,第K大的值为多少. 众数:区间里出现次数最多的数字,例如:1 1 2 2 2,区间[1 ...
- python基础语法7 闭包函数与装饰器
闭包函数: 1.闭包函数必须在函数内部定义 2.闭包函数可以引用外层函数的名字 闭包函数是 函数嵌套.函数对象.名称空间与作用域 结合体. # 直接传参 def func(x): print(x) f ...
- iis站点设置错误页面返回http状态码为404而不是302或其他
今天一位客户说网站错误页面返回的状态码是302而不是404,问ytkah要如何处理.这个应该是设置没有正确的原因.我们一步步来排查一下.1.首先打开iis管理器,左侧选择具体的站点,在右侧窗口中点击4 ...
- Mac下用命令行获取苹果手机的UDID
在终端输入命令行:system_profiler SPUSBDataType | grep "Serial Number:.*" | sed s#".*Serial Nu ...