zoukankan      html  css  js  c++  java
  • Android Shader渲染器:BitmapShader图片渲染

    public class BitmapShader extends Shader

    BitmapShader,  Shader家族的 专门处理图片渲染的


    构造方法:

    public BitmapShader(Bitmap bitmap, TileMode tileX, TileMode tileY)

       bitmap:原图

       tile直译为 瓷砖,瓦片。这里的TileMode 可看成是 铺图的模式。 

       tileX, tileY:x/y 方向铺图的模式


    public enum TileMode { 
        CLAMP   (0),
        REPEAT  (1),
        MIRROR  (2);
        TileMode(int nativeInt) {
            this.nativeInt = nativeInt;
        }
        final int nativeInt;
    }
      CLAMP:假设超出原始bounds(即原图的边界),则反复边缘上的color

      REPEAT:反复bitmap

      MIRROR:反复bitmap。与REPEAT不同的时,它是镜像反复,即:反向反复


    例:

    public class BitmapShaderView extends View {
    
        private BitmapShader mBitmapShader;
        private ShapeDrawable mShapeDrawable;
    
        public BitmapShaderView(Context context, Bitmap bitmap) {
            super(context);
    
            mBitmapShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
    
            mShapeDrawable = new ShapeDrawable(new OvalShape());
            mShapeDrawable.getPaint().setShader(mBitmapShader);
    //        mShapeDrawable.setBounds(0, 0, bitmap.getWidth(), bitmap.getHeight()); //原图大小
            mShapeDrawable.setBounds(0, 0, bitmap.getWidth() * 2, bitmap.getHeight() * 2);
        }
    
        @Override
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);
            canvas.drawColor(Color.CYAN);
    
            mShapeDrawable.draw(canvas);
        }
    }
      在Activity中,setContentView(new BitmapShaderView(context, bitmap));

    原图                                                                                                       效果图

       x和y 边缘反复


    改:mBitmapShader = new BitmapShader(bitmap, Shader.TileMode.MIRROR, Shader.TileMode.REPEAT);

    效果

     x方向镜像反复;y方向反复


    改:mBitmapShader = new BitmapShader(bitmap, Shader.TileMode.REPEAT, Shader.TileMode.MIRROR);
    效果:

     x方向反复。y方向镜像反复




  • 相关阅读:
    mysql的if 和 case when
    hive的日期和时间
    DVWA——XSS(Stored)(存储型跨站脚本)
    DVWA——XSS(Reflected)(反射型跨站脚本)
    DVWA——SQL Injection(Blind)(SQL盲注)
    转载一篇注入类型判断
    DVWA——SQL Injection(SQL注入)
    DVWA——Insecure CAPTCHA (不安全的验证码)
    DVWA——File Upload(文件上传)
    DVWA——File Inclusion(文件包含)
  • 原文地址:https://www.cnblogs.com/brucemengbm/p/7053369.html
Copyright © 2011-2022 走看看