• 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

  • 相关阅读:
    pandas,对dataFrame中某一个列的数据进行处理
    pandas的简单使用
    pandas,读取或存储DataFrames的数据到mysql中
    pandas,pd.ExcelWriter保存结果到已存在的excel文件中
    用命令让vbox的虚拟硬盘文件转换成vmware的vmdk
    vbox磁盘空间如何扩容
    Linux ext3/ext4数据恢复
    VirtualBox安装64位系统
    ubuntu 12.04启用休眠
    美化你的GRUB,全面支持中文(菜单、提示、帮助)适用7.04-9.04
  • 原文地址:https://www.cnblogs.com/dongweiq/p/11643645.html
Copyright © 2020-2023  润新知