码迷,mamicode.com
首页 > 移动开发 > 详细

Android的简易圆形头像

时间:2017-07-24 16:27:40      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:android   mod   mask   attr   简易   rgb   nal   import   circle   

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的简易圆形头像

标签:android   mod   mask   attr   简易   rgb   nal   import   circle   

原文地址:http://www.cnblogs.com/lonikitave/p/7229222.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!