android的20种滤镜效果代码,Android 图片 滤镜效果 通过矩阵实现

然,看到头像点击要加滤镜效果,有个新奇 的做法是用setColorFilter();

/**

* Created by yx on 16/4/3.

*/public class DiscolorImageView extends ImageView{    /**

* 变暗

*/

private final float[] SELECTED_DARK = new float[]

{1, 0, 0, 0, -80,            0, 1, 0, 0, -80,            0, 0, 1, 0, -80,            0, 0, 0, 1, 0};    /**

* 变亮

*/

private final float[] SELECTED_BRIGHT = new float[]

{1, 0, 0, 0, 80,                    0, 1, 0, 0, 80,                    0, 0, 1, 0, 80,                    0, 0, 0, 1, 0};    /**

* 高对比度

*/

private final float[] SELECTED_HDR = new float[]

{5, 0, 0, 0, -250,                    0, 5, 0, 0, -250,                    0, 0, 5, 0, -250,                    0, 0, 0, 1, 0};    /**

* 高饱和度

*/

private final float[] SELECTED_HSAT = new float[]

{(float) 3, (float) -2, (float) -0.2, 0, 50,

-1, 2, -0, 0, 50,

-1, -2, 4, 0, 50,                    0, 0, 0, 1, 0};    /**

* 改变色调

*/

private final float[] SELECTED_DISCOLOR = new float[]

{(float) -0.5, (float) -0.6, (float) -0.8, 0, 0,

(float) -0.4, (float) -0.6, (float) -0.1, 0, 0,

(float) -0.3, 2, (float) -0.4, 0, 0,                    0, 0, 0, 1, 0};    public DiscolorImageView(Context context) {

super(context);        this.setOnTouchListener(VIEW_TOUCH_DISCOLOR);

}    public DiscolorImageView(Context context, AttributeSet attrs) {

super(context, attrs);        this.setOnTouchListener(VIEW_TOUCH_DISCOLOR);

}    public DiscolorImageView(Context context, AttributeSet attrs, int defStyle) {

super(context, attrs, defStyle);        this.setOnTouchListener(VIEW_TOUCH_DISCOLOR);

}    public OnTouchListener VIEW_TOUCH_DISCOLOR = new OnTouchListener() {

@Override        public boolean onTouch(View v, MotionEvent event) {            if (event.getAction() == MotionEvent.ACTION_DOWN) {

ImageView iv = (ImageView) v;

iv.setColorFilter(new ColorMatrixColorFilter(SELECTED_HDR));              //iv.setColorFilter(new ColorMatrixColorFilter(SELECTED_BRIGHT));

//iv.setColorFilter(new ColorMatrixColorFilter(SELECTED_HDR));

//iv.setColorFilter(new ColorMatrixColorFilter(SELECTED_HSAT));

//iv.setColorFilter(new ColorMatrixColorFilter(SELECTED_DISCOLOR));

} else if (event.getAction() == MotionEvent.ACTION_UP) {

ImageView iv = (ImageView) v;

iv.clearColorFilter();

mPerformClick();

} else if (event.getAction() == MotionEvent.ACTION_CANCEL) {

ImageView iv = (ImageView) v;

iv.clearColorFilter();

}            return true;

}

};        private void mPerformClick() {

DiscolorImageView.this.performClick();

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值