【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群英传笔记——摘要,概述,新的出发点,温故而知新,能够为师矣!
- Android安装过程出现问题
- BwApp学习记录
- Andriod三步学会安卓自己定义视图及其属性
- Android HandlerThread 消息循环机制之源代码解析
- Android中的内部存储与外部存储
- 软件业的发展方向(云Web以及App)
- Android 完整开源应用大全,完整开源项目
- app安全测试初级