HSBImageView--android--可以设置HSB值的imageview

HSBImageView--android--可以设置HSB值的imageview,第1张

概述package guide.yunji.com.guide.view;import android.content.Context;import android.content.res.TypedArray;import android.graphics.ColorMatrix;import android.graphics.ColorMatrixColorFilter;i
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,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,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,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全部内容,希望文章能够帮你解决HSBImageView--android--可以设置HSB值的imageview所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1121418.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-29
下一篇2022-05-29

发表评论

登录后才能评论

评论列表(0条)

    保存