Android图形处理-百变Paint

本文介绍了Android中Paint对象的高级用法,包括设置阴影、渐变、画笔效果如PathEffect,以及MaskFilter的模糊和突出化效果。通过示例代码展示了如何创建线性渐变、设置阴影、绘制五角星虚线以及实现文字沿路径绘制。同时,还提到了在光棍节制作闪动红心的技巧。
摘要由CSDN通过智能技术生成

Android图形处理-百变Paint

Paint的基本属性

Android图形处理-Canvas已经有了基本的使用,但是这节介绍几个好玩的属性

设置阴影和渐变

设置渐变

主要是给画笔(Paint)设置一个Shader

sp161108_143636

        Paint paint = new Paint();
        LinearGradient linearShader = new LinearGradient(0, 0, 100, 100,
                new int[]{Color.RED, Color.BLACK, Color.BLUE, Color.DKGRAY},
                null, Shader.TileMode.CLAMP);
        paint.setShader(linearShader);
        canvas.drawCircle(100,100,100,paint);

LinearGradient是Shader的子类。其他子类:

sp161108_142705

LinearGradient构造方法的含义:

    /** Create a shader that draws a linear gradient along a line.
        @param x0           The x-coordinate for the start of the gradient line
        @param y0           The y-coordinate for the start of the gradient line
        @param x1           The x-coordinate for the end of the gradient line
        @param y1           The y-coordinate for the end of the gradient line
        @param  colors      The colors to be distributed along the gradient line
        @param  positions   May be null. The relative positions [0..1] of
                            each corresponding color in the colors array. If this is null,
                            the the colors are distributed evenly along the gradient line.
        @param  tile        The Shader tiling mode
    */

前两个参数是开始点,接下来是结束点,colors是颜色的数组,positions是分布的模式,tile是渐变的模式比如可重复等

设置阴影
        paint.setShadowLayer(100,20,20,Color.RED);
        paint.setColor(getResources().getColor(R.color.colorAccent));
        canvas.drawCircle(100,100,50,paint);

核心是setShadowLayer

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值