• 3.24


    最简单的绘制圆形的ImageView:

    package com.jay.demo.imageviewdemo;
    
    import android.content.Context;
    import android.graphics.Bitmap;
    import android.graphics.Canvas;
    import android.graphics.Paint;
    import android.graphics.PaintFlagsDrawFilter;
    import android.graphics.Path;
    import android.graphics.Rect;
    import android.graphics.Region;
    import android.util.AttributeSet;
    import android.widget.ImageView;
    
    /**
     * Created by coder-pig on 2015/7/18 0018.
     */
    public class RoundImageView extends ImageView {
    
        private Bitmap mBitmap;
        private Rect mRect = new Rect();
        private PaintFlagsDrawFilter pdf = new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG);
        private Paint mPaint = new Paint();
        private Path mPath=new Path();
        public RoundImageView(Context context, AttributeSet attrs) {
            super(context, attrs);
            init();
        }
    
    
        //传入一个Bitmap对象
        public void setBitmap(Bitmap bitmap) {
            this.mBitmap = bitmap;
        }
    
    
        private void init() {
            mPaint.setStyle(Paint.Style.STROKE);
            mPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
            mPaint.setAntiAlias(true);// 抗锯尺
        }
    
    
        @Override
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);
            if(mBitmap == null)
            {
                return;
            }
            mRect.set(0,0,getWidth(),getHeight());
            canvas.save();
            canvas.setDrawFilter(pdf);
            mPath.addCircle(getWidth() / 2, getWidth() / 2, getHeight() / 2, Path.Direction.CCW);
            canvas.clipPath(mPath, Region.Op.REPLACE);
            canvas.drawBitmap(mBitmap, null, mRect, mPaint);
            canvas.restore();
        }
    }
  • 相关阅读:
    克如斯卡尔 P1546
    真正的spfa
    第四课 最小生成树 要点
    关于vscode中nullptr未定义
    cmake学习笔记
    python学习笔记
    (BFS 图的遍历) 2906. kotori和迷宫
    (图论基础题) leetcode 997. Find the Town Judge
    (BFS DFS 并查集) leetcode 547. Friend Circles
    (BFS DFS 图的遍历) leetcode 841. Keys and Rooms
  • 原文地址:https://www.cnblogs.com/20193898liufa/p/14908715.html
Copyright © 2020-2023  润新知