zoukankan      html  css  js  c++  java
  • 将头图片变成圆形简单实现

    package com.loaderman.customviewdemo;
    
    import android.content.Context;
    import android.graphics.*;
    import android.util.AttributeSet;
    import android.view.View;
    
    
    public class AvatorView extends View {
        private Paint mPaint;
        private Bitmap mBitmap;
        private BitmapShader mBitmapShader;
    
        public AvatorView(Context context, AttributeSet attrs) throws Exception{
            super(context, attrs);
            mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.avator);
            mPaint = new Paint();
            mBitmapShader = new BitmapShader(mBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
        }
    
        @Override
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);
            Matrix matrix = new Matrix();
            float scale = (float) getWidth()/mBitmap.getWidth();
            matrix.setScale(scale,scale);
            mBitmapShader.setLocalMatrix(matrix);//设置坐标变换矩阵
            mPaint.setShader(mBitmapShader);
    
            float half = getWidth()/2;
            canvas.drawCircle(half,half,getWidth()/2,mPaint);
        }
    }
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center"
        android:gravity="center"
        android:background="@android:color/white"
        >
    
    
     <com.loaderman.customviewdemo.AvatorView
         android:layout_width="200dp"
         android:layout_height="200dp" />
    </LinearLayout>

  • 相关阅读:
    CTF-Reverse-[GXYCTF2019]luck_guy
    凸度偏差与收益率曲线
    【翻译】理解 LSTM 网络
    基于 Keras 用 LSTM 网络做时间序列预测
    AIMR 固定收益推荐读物
    基于 Keras 用深度学习预测时间序列
    预测美国债券回报
    久期增加会提高长期预期回报吗?
    市场收益率预期与远期收益率
    sql server 查询时会锁表吗?
  • 原文地址:https://www.cnblogs.com/loaderman/p/10213019.html
Copyright © 2011-2022 走看看