class MyView extends View{ // 앞서 만든 레이아웃에 저장하기 위한 클래스
ArrayList<Integer> list;
Point point = new Point();
public Paint paint = new Paint();
Path path = new Path(); // 이미 그어진 선을 저장하기 위한 객체
public Paint paint2 = new Paint();
Path path3 = new Path();
Path path2 = new Path();
Paint eraserPaint = new Paint();
static int color123;
static int num;
public MyView(Context context) {
super(context);
paint.setStyle(Paint.Style.STROKE); // 선을 긋게 하는 부분
paint.setStrokeWidth(10f);// 선의 굵기 설정
paint2.setStyle(Paint.Style.STROKE);
paint2.setStrokeWidth(10f);
paint2.setColor(0xffff2133);
}
protected void onDraw(Canvas canvas) { // 화면을 그려주는 메서드
if (color123 == 1) {
canvas.drawPath(path, paint);
(paint).setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
// 저장된 path 를 그려라
}
invalidate();
if (color123 == 2) {
canvas.drawPath(path2, paint2);
}
if (color123 == 3) {
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {
float x = event.getX();
float y = event.getY();
switch(event.getAction()) {
case MotionEvent.ACTION_DOWN:
path.moveTo(x, y);
path2.moveTo(x, y);
path3.moveTo(x, y);
// 위치 이동
break;
case MotionEvent.ACTION_MOVE:
path.lineTo(x, y);
path2.lineTo(x, y);
path3.lineTo(x, y);
// 위치에 선을 남기는 부분
break;
case MotionEvent.ACTION_UP:
break;
}
return true;
}
색상을 바꿀때마다 기존에 있던것이 바뀌어서 안바뀌도록 저장하고 진행을 해야한다는데, 어떻게 진행해야하는지 모르겠습니다. 지우개도 부탁드립니다.