안드로이드 개발 질문/답변
(글 수 45,052)
아래 소스와 같이 그리고지우는것은 성공 하였는데
지울떄 paint를 mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); 로
바꾸고 지우면 지우는 순간(move) 지워지지 않고 손을떄는순간(touch_up)하는순간 지워지더군요
move할때 계속 지원지게 하려면 어떻한 방법이 있을까요?
조언 부탁 드리겠습니다
mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setDither(true); mPaint.setColor(0xFF000000); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeCap(Paint.Cap.ROUND); mPaint.setStrokeWidth(12);
class MyView extends View { Context context; private Canvas mCanvas; private static final String TAG = "MyView";
public MyView(Context context) { super(context); this.context = context; mBitmap = Bitmap.createBitmap(480, 800, Bitmap.Config.ARGB_8888); mBitmapPaint = new Paint(Paint.DITHER_FLAG); mPath = new Path(); mCanvas = new Canvas(mBitmap); }
public void onDraw(Canvas canvas) {
Log.i(TAG, "onDraw"); canvas.drawColor(Color.WHITE); // canvas. // for (int i = 0; i < list.size(); i++) { // if (list.get(i).isDraw) { // canvas.drawLine(list.get(i - 1).x, list.get(i - 1).y, // list.get(i).x, list.get(i).y, mPaint); // } // } canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
canvas.drawPath(mPath, mPaint); }
public void setColor(int color) { mPaint.setColor(color); }
private void touch_start(float x, float y) { mPath.reset(); mPath.moveTo(x, y); mX = x; mY = y; }
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 mPath.reset(); }
@Override public boolean onTouchEvent(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; } }