android paint对象,关于Android Paint绘图颜色

DrawView.

java

public class DrawView extends View implements OnTouchListener {

private Canvas mCanvas;

private Path mPath;

public Paint mPaint;

ArrayList paths = new ArrayList();

private ArrayList undonePaths = new ArrayList();

private MaskFilter mEmboss;

private MaskFilter mBlur;

private Bitmap im;

public DrawView(Context context) {

super(context);

setFocusable(true);

setFocusableInTouchMode(true);

this.setOnTouchListener(this);

paths.clear();

undonePaths.clear();

mPaint = new Paint();

mPaint.setAntiAlias(true);

mPaint.setDither(true);

mPaint.setColor(Color.BLUE);

mPaint.setStyle(Paint.Style.STROKE);

mPaint.setStrokeJoin(Paint.Join.ROUND);

mPaint.setStrokeCap(Paint.Cap.ROUND);

mPaint.setStrokeWidth(4);

mEmboss = new EmbossMaskFilter(new float[] { 1,1,1 },0.4f,6,3.5f);

mBlur = new BlurMaskFilter(8,BlurMaskFilter.Blur.NORMAL);

mCanvas = new Canvas();

mPath = new Path();

// paths.add(mPath);

im = BitmapFactory.decodeResource(context.getResources(),R.drawable.ic_launcher);

}

@Override

protected void onSizeChanged(int w,int h,int oldw,int oldh) {

super.onSizeChanged(w,h,oldw,oldh);

}

@Override

protected void onDraw(Canvas canvas) {

canvas.drawColor(Share.cColor);

for (Path p : paths) {

canvas.drawPath(p,mPaint);

}

canvas.drawPath(mPath,mPaint);

}

private float mX,mY;

private static final float TOUCH_TOLERANCE = 4;

private void touch_start(float x,float y) {

mPaint.setColor(Share.dColor);

undonePaths.clear();

mPath.reset();

mPath.moveTo(x,y);

mX = x;

mY = y;

Log.e("","pathsize:::" + paths.size());

Log.e("","undonepathsize:::" + undonePaths.size());

}

private void touch_move(float x,float y) {

float dx = Math.abs(x - mX);

float dy = Math.abs(y - mY);

if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) {

mPath.quadTo(mX,mY,(x + mX) / 2,(y + mY) / 2);

mX = x;

mY = y;

}

}

private void touch_up() {

mPath.lineTo(mX,mY);

// commit the path to our offscreen

mCanvas.drawPath(mPath,mPaint);

// kill this so we don't double draw

paths.add(mPath);

mPath = new Path();

Log.e("","undonepathsize:::" + undonePaths.size());

}

public void onClickUndo() {

Log.e("","undonepathsize:::" + undonePaths.size());

if (paths.size() > 0) {

undonePaths.add(paths.remove(paths.size() - 1));

invalidate();

} else {

}

// toast the user

}

public void onClickRedo() {

Log.e("","undonepathsize:::" + undonePaths.size());

if (undonePaths.size() > 0) {

paths.add(undonePaths.remove(undonePaths.size() - 1));

invalidate();

} else {

}

// toast the user

}

@Override

public boolean onTouch(View arg0,MotionEvent event) {

float x = event.getX();

float y = event.getY();

switch (event.getAction()) {

case MotionEvent.ACTION_DOWN:

touch_start(x,y);

invalidate();

break;

case MotionEvent.ACTION_MOVE:

touch_move(x,y);

invalidate();

break;

case MotionEvent.ACTION_UP:

touch_up();

invalidate();

break;

}

return true;

}

}

我试图绘制不同颜色的手指画,但每当我改变颜色的油漆然后所有以前的路径或绘图得到和绘制更新的颜色我想用不同的颜色绘制我该怎么办?请给我一些解决方案.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值