Android图形图像之以Bitmap作为Canvas画布的材料

概述

当以Bitmap作为画布材料时,可以绘制出以下各种图案:

demo/** * 图形图像处理:在Bitmap上绘画 */{private int width;private int height;private Paint mPaintCircle;private Paint mPaintRect;private Bitmap mBitmap;private Canvas mCanvasBm;public MyBitMapViewSec(Context context) {super(context);}public MyBitMapViewSec(Context context, AttributeSet attrs) {super(context, attrs);mPaintCircle = new Paint();mPaintCircle.setColor(Color.YELLOW);mPaintRect = new Paint();mPaintRect.setColor(Color.GREEN);//XOR:交叠和被交叠部分均不显示;DST_OVER:自身交叠部分不显示;SRC_OVER交叠部分只显示自己PorterDuffXfermode mode = new PorterDuffXfermode(PorterDuff.Mode.XOR);mPaintRect.setXfermode(mode);}(int widthMeasureSpec, int heightMeasureSpec) {super.onMeasure(widthMeasureSpec, heightMeasureSpec);width = getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec);height = getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec);setMeasuredDimension(width, height);//参数:画布宽、长尺寸和格式mBitmap = Bitmap.createBitmap(width,height, Bitmap.Config.ARGB_8888);mCanvasBm = new Canvas(mBitmap);//自定义一个画布,画布材料是Bitmap对象}(Canvas canvas) {super.onDraw(canvas);canvas.drawColor(Color.RED);//先在bitmap上画mCanvasBm.drawCircle(width / 2, height / 2, width / 2, mPaintCircle);mCanvasBm.drawRect(0,0,width/2,width/2,mPaintRect);//将画好的bitmap画出来canvas.drawBitmap(mBitmap,0,0,null);//这一步必不可少}}

结果演示: PorterDuffXfermode mode = new PorterDuffXfermode(参数); 参数为PorterDuff.Mode.DST_OVEL时:

参数为PorterDuff.Mode.XOR时:

,带着我的相机和电脑,远离繁华,走向空旷。

Android图形图像之以Bitmap作为Canvas画布的材料

相关文章:

你感兴趣的文章:

标签云: