안녕하세요,,


개발자가 꿈인 대학생입니다..


지금 그림판 예제를 만들고 있는데,, (안드로이드펍에 있는 예제를 참고했습니다.)


윈도우 그림판에 있는 선그리기를 똑같이 만들어 보려고 했는데;;


선을 하나 그리고 다른 선을 그리려고 하면,, 이전에 그린 선이 없어져 버리네요,,


만들다 보니 도통 뭐가 문제인지 모르겠네여,, 고수님들 도움 부탁드립니다.





---------------------------------------------------------------



public class CreativePainterActivity extends Activity {

//

//private MyView vw;

Paint mPaint;

//

/*

//--Public constants used to specify shape being drawn

public static final int _NONE      = 0;

public static final int _LINE      = 1;

public static final int _RECTANGLE = 2;

public static final int _CIRCLE    = 3;

public static final int _ERASER    = 4;

*/

//--Variables to store the current figure info

private float _currentStartX;       //where mouse first pressed

private float _currentStartY;

private float _currentEndX;         //where dragged to or released

private float _currentEndY;

    /** Called when the activity is first created. */

    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        //setContentView(R.layout.main);

        //vw = new MyView(this);

        //setContentView(vw);

        }

    

@Override

protected void onResume() {

// TODO Auto-generated method stub

super.onResume();

setContentView(new MyView(this));

mPaint = new Paint();

mPaint.setAntiAlias(true);

mPaint.setDither(true);

mPaint.setColor(0xFFFFFF00);

mPaint.setStyle(Paint.Style.STROKE);

mPaint.setStrokeJoin(Paint.Join.ROUND);

mPaint.setStrokeCap(Paint.Cap.ROUND);

mPaint.setStrokeWidth(8);

}

    //view class

    public class MyView extends View{


     private Canvas mCanvas;

     private Bitmap mBitmap;

private Paint mBitmapPaint;

Bitmap bm;

    

     //private Paint mBitmapPaint;

    

     public MyView(Context context){

     super(context);

    

    

     //ADDED

     DisplayMetrics metrics = new DisplayMetrics();

getWindowManager().getDefaultDisplay().getMetrics(metrics);


mBitmap = Bitmap.createBitmap(metrics.widthPixels, metrics.heightPixels, Bitmap.Config.ARGB_8888);

mCanvas = new Canvas(mBitmap);

mBitmapPaint = new Paint(Paint.DITHER_FLAG);

mCanvas.drawColor(0xFFFFFFFF);

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

     //initializing Paint object


     //mPaint = new Paint();

     //mPaint.setColor(Color.BLUE);

     //mPaint.setStrokeWidth(3);

     //mPaint.setAntiAlias(true);

     }


    

    public void onDraw(Canvas canvas){

     //canvas.drawColor(Color.LTGRAY);

     canvas.drawBitmap(bm, 0, 0, mBitmapPaint);

     canvas.drawLine(_currentStartX_currentStartY_currentEndX_currentEndYmPaint);

    }

    

    //Methods for touch events

    public boolean onTouchEvent(MotionEvent event){

     if (event.getAction() == MotionEvent.ACTION_DOWN){

     _currentStartX=event.getX();

     _currentStartY=event.getY();

     return true;

     }

    

     if(event.getAction() == MotionEvent.ACTION_MOVE){

     _currentEndX=event.getX();

     _currentEndY=event.getY();

     invalidate(); //this is important!

     return true;

     }

     if(event.getAction() == MotionEvent.ACTION_UP){

     _currentEndX=event.getX();

     _currentEndY=event.getY();

     mCanvas.drawLine(_currentStartX_currentStartY_currentEndX_currentEndYmPaint);

     invalidate();

     //this.invalidate(); //this is important!

     return true;

     }   

     return true;

    }

    

    }//end of the class MyView

    

}//end of the class CreativePainterActivity