zoukankan      html  css  js  c++  java
  • Android渲染器Shader:梯度渐变扫描渲染器SweepGradient(二)

    

    Android渲染器Shader:梯度渐变扫描渲染器SweepGradient(二)

    附录文章1介绍了线性渐变渲染器。
    Android的SweepGradient梯度渐变扫描,重点是在构造SweepGradient的中心点选择。我写一个例子。

    package zhangphil.demo;
    
    import android.content.Context;
    import android.graphics.Canvas;
    import android.graphics.Color;
    import android.graphics.Paint;
    import android.graphics.SweepGradient;
    import android.util.AttributeSet;
    import android.view.View;
    
    /**
     * Created by Phil on 2016/7/25.
     */
    
    
    public class SweepGradientView extends View {
    
        private Paint mPaint = null;
    
        // 梯度渐变扫描渲染
        private SweepGradient mSweepGradient = null;
    
        public SweepGradientView(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
        @Override
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);
    
            mSweepGradient = new SweepGradient(this.getWidth() / 2, this.getHeight() / 2, new int[]{Color.TRANSPARENT, Color.RED, Color.TRANSPARENT, Color.YELLOW, Color.BLUE}, null);
            mPaint = new Paint();
            mPaint.setAntiAlias(true);
    
            mPaint.setShader(mSweepGradient);
    
            canvas.drawCircle(this.getWidth() / 2, this.getHeight() / 2, 300, mPaint);
        }
    }
    


    SweepGradientView直接像附录文章1那样在上层的activity里面new出来一个对象,然后setContentView进去即可。


    代码运行结果:


    附录文章:
    1,《Android渲染器Shader:LinearGradient(一)》链接:http://blog.csdn.net/zhangphil/article/details/52004027


  • 相关阅读:
    AI
    CentoOS6.6安装netcat
    ip防刷脚本
    php git pull
    冥想_ PHP抽奖程序概率算法
    如何在CentOS配置Apache的HTTPS服务
    C++ 用RGB 三种颜色绘图
    Linux Vsftpd 连接超时解决方法(被动模式)
    js 函数返回函数
    模拟jquery的$()选择器的实现
  • 原文地址:https://www.cnblogs.com/hehehaha/p/6147278.html
Copyright © 2011-2022 走看看