打算 找几篇吊的 文章,跑一跑就通了
1.入门1
Paint mPaint = new Paint();
mPaint.setColor(Color.BLUE);
canvas.drawCircle(300,300 , 300, mPaint);
mPaint.setColor(Color.RED);
RectF rectF = new RectF(300, 300, 700, 700);
canvas.drawRect(rectF,mPaint);
这里边有重合的
setLayerType(View.LAYER_TYPE_SOFTWARE, null);
canvas.drawARGB(255, 139, 197, 186);
Paint mPaint = new Paint();
mPaint.setColor(Color.BLUE);
canvas.drawCircle(300,300 , 300, mPaint);
//使用CLEAR作为PorterDuffXfermode绘制蓝色的矩形
mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
mPaint.setColor(Color.RED);
RectF rectF = new RectF(300, 300, 700, 700);
canvas.drawRect(rectF,mPaint);
//最后将画笔去除Xfermode
mPaint.setXfermode(null);
第一行那个必须写,貌似硬件加速和这个冲突
setLayerType(View.LAYER_TYPE_SOFTWARE, null);
int layerId = canvas.saveLayer(0, 0, getWidth(), getHeight(), null, Canvas.ALL_SAVE_FLAG);
Paint mPaint = new Paint();
mPaint.setColor(Color.BLUE);
canvas.drawCircle(300,300 , 300, mPaint);
//使用CLEAR作为PorterDuffXfermode绘制蓝色的矩形
mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
mPaint.setColor(Color.RED);
RectF rectF = new RectF(300, 300, 700, 700);
canvas.drawRect(rectF,mPaint);
//最后将画笔去除Xfermode
mPaint.setXfermode(null);
canvas.restoreToCount(layerId);
setLayerType(View.LAYER_TYPE_SOFTWARE, null);
int layerId = canvas.saveLayer(0, 0, getWidth(), getHeight(), null, Canvas.ALL_SAVE_FLAG);
Paint mPaint = new Paint();
mPaint.setColor(Color.BLUE);
canvas.drawCircle(300,300 , 300, mPaint);
//使用CLEAR作为PorterDuffXfermode绘制蓝色的矩形
mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.XOR));
mPaint.setColor(Color.RED);
RectF rectF = new RectF(300, 300, 700, 700);
canvas.drawRect(rectF,mPaint);
//最后将画笔去除Xfermode
mPaint.setXfermode(null);
canvas.restoreToCount(layerId);
这图我偷的
先画三个波浪
public class MyoWaveView extends View {
private Paint mPaint;
private int bochang=300;//波长 一朵浪花的 宽度
private int bogao=200; //波高 一朵浪花的 高度
private Path path;
public MyoWaveView(Context context) {
this(context, null);
}
public MyoWaveView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public MyoWaveView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mPaint = new Paint();
mPaint.setColor(Color.BLUE);
mPaint.setStyle(Paint.Style.FILL);
mPaint.setAntiAlias(true);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
int height = getHeight();
int y = height / 2;
path = new Path();
path.moveTo(0, y);
path.quadTo(bochang/2,bogao,bochang,y);
path.quadTo(bochang+bochang/2,bogao,bochang*2,y);
path.quadTo(bochang+bochang+bochang/2,bogao,bochang*3,y);
path.lineTo(bochang*3,height);
path.lineTo(0,height);
path.close();
canvas.drawPath(path, mPaint);
}
}
紧接着画一个大圆
//画一个大圆
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeWidth(5);
mPaint.setColor(Color.YELLOW);
canvas.drawCircle(getWidth()/2,getHeight()/2,getWidth()/2,mPaint);
然后Xfermode 只要重合的,额,失败了,留个纪念