Android ColorMatrix 变换 饱和度 缩放

来源:互联网 发布:潘多拉 pppoe mac 编辑:程序博客网 时间:2024/06/10 04:22

矩阵的一些操作

    @Override    protected void onDraw(Canvas canvas) {        //关闭硬件加速        setLayerType(View.LAYER_TYPE_SOFTWARE,null);        //NORMAL: 内外都模糊绘制        Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);        paint.setColor(Color.RED);        //图片        Bitmap resource = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);        //绘制原图        canvas.drawBitmap(resource,100,100,paint);        //设置颜色过滤器        ColorMatrix matrix = new ColorMatrix();        paint.setColorFilter(new ColorMatrixColorFilter(matrix));        canvas.drawBitmap(resource,500,100,paint);    }

常用的一些API

Colormatrix 类中的方法    /**     * 色彩缩放     */    public void setScale(float rScale, float gScale, float bScale,float aScale) {}    /**     * 饱和度设置     * 0 == 灰色图片     * 1 == 保持不变     * >1 增加饱和度     */    public void setSaturation(float sat) {}    /**     * 色彩旋转     * @axis 绕着那个轴旋转(0,1,2)     * <code>axis=0</code> 绕着红轴     * <code>axis=1</code> 绕着绿轴     * <code>axis=2</code> 绕着蓝轴     * @degrees   旋转的度数     */    public void setRotate(int axis, float degrees) {}