首页 > 代码库 > Android的简易圆形头像
Android的简易圆形头像
package com.example.administrator.test.Five.Second;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.util.AttributeSet;
import android.view.View;
import com.example.administrator.test.R;
/**
* Created by Administrator on 2017/7/21.
*/
public class AnomalousPhotoView extends View {
private Bitmap bmpCat;
private Bitmap bmpMask;
private Bitmap bmpresult;
Canvas c_bmpcat;
Canvas c_bmpmask;
Canvas c_result;
private Paint paint;
private static final int OFFSET=10;
public AnomalousPhotoView(Context context, AttributeSet attrs){
super(context,attrs);
bmpCat= BitmapFactory.decodeResource(context.getResources(), R.drawable.luoluo);
bmpMask= Bitmap.createBitmap(bmpCat.getWidth(),bmpCat.getHeight(), Bitmap.Config.ARGB_8888);
c_bmpmask=new Canvas(bmpMask);
paint=new Paint(Paint.ANTI_ALIAS_FLAG);
}
@Override
protected void onDraw(Canvas canvas){
super.onDraw(canvas);
int id=canvas.saveLayer(0,0,bmpCat.getWidth(),bmpCat.getHeight(),null,Canvas.ALL_SAVE_FLAG);
canvas.drawBitmap(bmpCat,0,0,null);
paint.setColor(Color.BLUE);
c_bmpmask.drawCircle(bmpCat.getWidth()/2,bmpCat.getHeight()/2,200,paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
//canvas.drawCircle(100,100,100,paint);
canvas.drawBitmap(bmpMask,0,0,paint);
canvas.restoreToCount(id);
}
}
Android的简易圆形头像
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。